dmikester1 – 22-28 Jan 13

I have an array of objects. Each object has many fields, but I want to update the linePosition field in all of the objects. I simply want to decrement it by one. Would map be my best bet here?
D
dmikester1460d ago
If it matters, this array is a React state array.
S
ScriptyChris460d ago
You can simple do a loop
for (const object of array) {
object.property_to_update = 'new value';
}
for (const object of array) {
object.property_to_update = 'new value';
}
Oh, in this case use functional update with .map() to avoid state mutation
setState(prev => prev.map((obj) => ({
...obj,
property_to_update: 'new value'
})));
setState(prev => prev.map((obj) => ({
...obj,
property_to_update: 'new value'
})));
UU
Unknown User459d ago