merge javascript objects javascript code example
Example 1: merge objects javascript
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };
const ad = { ...a, ...d }; // { b: 1, c: 2, e: 1, f: 2 }
Example 2: two object combine together javascript
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };
const ad = { ...a, ...d }; // { b: 1, c: 2, e: 1, f: 2 }
let objs = [{firstName: "Steven"}, {lastName: "Hancock"}, {score: 85}];
let obj = objs.reduce(function(acc, val) {
return Object.assign(acc, val);
},{});