Created
August 30, 2017 14:19
-
-
Save aherve/5495b52f457090dedad91e210fb0f18e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// update an object in array by property | |
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 } ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment