Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const initial = [ {id: 1, score: 1}, {id: 2, score: 2}, {id: 3, score: 4}]
- const newValue = {id: 3, score: 3}
- const updated = initial.map(x => x.id === newValue.id ? newValue : x)
- console.log(updated) // => [ { id: 1, score: 1 }, { id: 2, score: 2 }, { id: 3, score: 3 } ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement