How can I rename an element of an array if this element contains a given string?
So e.g. I have an array in my state:
constructor(props) {
super(props);
this.state = {
array: ["stack", "overflow", "question"],
}
}
and now I wanna replace the string question
with e.g. answer
. So I could easily do this if the index of question
is always the same but how can I replace question
with answer
if question always have an other index? This should be done in the most efficient way. Hope anyone can help me.
Thanks