Skip to content

Instantly share code, notes, and snippets.

@asm-jaime
Created August 17, 2016 16:49
Show Gist options
  • Save asm-jaime/f7a8da77c6e2a4e7e379de00eba3fcb6 to your computer and use it in GitHub Desktop.
Save asm-jaime/f7a8da77c6e2a4e7e379de00eba3fcb6 to your computer and use it in GitHub Desktop.
updating array objects from otcher objects on id
'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