0👍
✅
You can achive this using map.
Try this code.
state.posts = state.posts.map(function (post) {
if (post.id === incoming.id) {
return incoming
}
return item
})
0👍
You could try changing your “Array of Objects” to and “Object of Objects” and giving every Object a key like this:
{
1: {
.....
},
2: {
.....
}
....
}
then you can add objects to them by calling them by their key which should be the same as the id.
Source:stackexchange.com