Given
const allPost = [{_id: "uniqueId1", "name": "Bob"}, {_id: "uniqueId2", "name": "Sam"}]
const changeTo = {_id: "uniqueId1", "name": "Tim"}
I want to change to the given allPost object so it becomes
const allPost = [{_id: "uniqueId1", "name": "Tim"}, {_id: "uniqueId2", "name": "Sam"}]
I tried this but it does not work
const allPost = [{_id: "uniqueId1", "name": "Bob"}, {_id: "uniqueId2", "name": "Sam"}]
const changeTo = {_id: "uniqueId1", "name": "Tim"}
const newPost = allPost.filter((post) => {
if(post._id === changeTo._id) {
post = changeTo
}
})
Anyway to accomplish this?