How to update an element in an es6 array?

I have an array of objects and I want to change the property in the object.

I know that we can delete an object using the splice.Is function is the only option for deleting and adding it back?

+5
source share
2 answers

You must change it directly (assuming you know the index)

YourArray[index].ObjectProperty = YourValue 

It doesn't matter if it's ES6 or not.

+4
source

If all you have to do is change the support in the object, there is no need to remove it from the array.

 arr[2].prop = newValue; 
0
source

Source: https://habr.com/ru/post/1243374/


All Articles