I've an array of objects and I want to modify a property in the object.
I know we can remove the object using splice function.Is the only option to remove and add it back?
I've an array of objects and I want to modify a property in the object.
I know we can remove the object using splice function.Is the only option to remove and add it back?
array[index].property = value
... or, as the question implies, to replace an object ... array[index] = newobject
– Jaromanda X
Commented
Feb 19, 2016 at 7:45
You have to modify it directly (assuming You know index)
YourArray[index].ObjectProperty = YourValue
It does not make any difference if it's ES6 or not
If all you need to do is modify a prop in the object, theres no need to remove it from the array.
arr[2].prop = newValue;