SHARE
TWEET

Untitled

a guest Sep 14th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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  }  ]
RAW Paste Data
Top