Created
August 17, 2016 16:49
-
-
Save asm-jaime/f7a8da77c6e2a4e7e379de00eba3fcb6 to your computer and use it in GitHub Desktop.
updating array objects from otcher objects on id
This file contains hidden or 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
'use strict' | |
const objects = [{ | |
channel: { | |
id: "first" | |
} | |
}, { | |
channel: { | |
id: "second", | |
props: "old value" | |
} | |
}]; | |
const upd_objects = [{ | |
id: "first", | |
props: "new value" | |
}, { | |
id: "second", | |
props: "new value" | |
}]; | |
objects.map((e) => { | |
const some_obj = upd_objects.find((g) => (e.channel.id === g.id)); | |
if (some_obj) { | |
Object.assign(e.channel, some_obj); | |
}; | |
}); | |
console.log(objects); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment