I using react to build my page
I have array['kiwi','papaya','apple']
And I using these code
if(this.state.recordFood.indexOf('kiwi') !=-1){
this.setState({
feedbackDisplay: [...this.state.feedbackDisplay,this.state.feedback[0].content]
})
};
if(this.state.recordFood.indexOf('papaya') !=-1){
this.setState({
feedbackDisplay: [...this.state.feedbackDisplay,this.state.feedback[1].content]
})
};
if(this.state.recordFood.indexOf('apple') !=-1){
this.setState({
feedbackDisplay: [...this.state.feedbackDisplay,this.state.feedback[2].content]
})
};
if there is kiwi papaya apple in my array , it will concat different value to state feedbackdisplay, so after the code , I will have
this.state.feedback[0].content
this.state.feedback[1].content
this.state.feedback[2].content
in my state feedbackdisplay
but it all concat this.state.feedback[0].content to state feedback display
so I got
this.state.feedback[0].content
this.state.feedback[0].content
this.state.feedback[0].content
in my state feedbackdisplay