I have this array of objects:
const indexStates = [ {"4": true}, {"3": false}, {"7": false}, {"1": true} ];
and am trying to figure out how to change the value in a given object in this original array (do not want to make a copy of the array). I have tried this
index = 4;
indexStates.filter(o => o[index] = !o[index]);
console.log(indexStates);
but the result is
[{"4": false}, {"3": false, "4": true}, {"4": true, "7": false}, {"1": true, "4": true}]
instead of changing the value only in {"4": false} and leaving the other objects as is. What am I doing wrong? Also, I don't want to use third party libraries for this operation.
filterfor side effects.filter's purpose is to take an array and create a new array with some of the elements removed (filtered).[{key: 4, value: false}, {key: 3, value: false}...and so I'm finding it difficult to work with because the keys are dynamic in a sense.if (index in projects[i]) {instead ofif (projects[i].value == value) {.