Simple question, I am sure that I am being stupid and it is an easy fix. Have an array of objects and want to access each object's vis value and change it through my for loop. I don't understand why it doesn't work.
onSearch = keyWord => {
let newMarkers = this.state.markers;
for (let i = 0; i<this.state.markers.length;i++) {
if (this.state.markers[i].name.toLowerCase().includes(keyWord.toLowerCase())) {
newMarkers[i].vis = true;
} else {
newMarkers[i].vis = false;
}
}
console.log(newMarkers);
//console.log to see if the vis value has been changed: spoiler alert it hasn't :(
this.setState({markers: newMarkers});
console.log(this.state.markers)
}