Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. const initial = [ {id: 1, score: 1}, {id: 2, score: 2}, {id: 3, score: 4}]
  2. const newValue = {id: 3, score: 3}
  3. const updated = initial.map(x => x.id === newValue.id ? newValue : x)
  4. 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