Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update an element in a es6 array?

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?

like image 998
bharz629 Avatar asked Sep 26 '22 08:09

bharz629


1 Answers

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

like image 63
entio Avatar answered Oct 20 '22 07:10

entio