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
varstate=[{name: "Goran"},{name: "Peter"}]// you can use es6 Array.prototype.findIndex to find index of the object// let index = state.findIndex(({name}) => name === "Peter");varindex=1;varfield='name';varvalue='Zika';varnewState=[
...state.slice(0,index),{
...state[index],[field]: value},
...state.slice(index+1)];console.log(newState);/* [ {name: "Goran"}, {name: "Zika"} ]*/