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?
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
如果您只需要修改对象中的prop,则无需将其从数组中删除。
arr[2].prop = newValue;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.