You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
update array with objects using Array.prototype.slice
var state = [
{name: "Goran"},
{name: "Peter"}
]
// you can use es6 Array.prototype.findIndex to find index of the object
// let index = state.findIndex(({name}) => name === "Peter");
var index = 1;
var field = 'name';
var value = 'Zika';
var newState = [
...state.slice(0, index),
{
...state[index],
[field]: value
},
...state.slice(index + 1)
];
console.log(newState);
/*
[
{name: "Goran"},
{name: "Zika"}
]
*/