hjavascript merge objects code example
Example 1: merge objects javascript
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };
const ad = { ...a, ...d };
Example 2: javascript merge objects
function mergeObj(...arr){
return arr.reduce((acc, val) => {
return { ...acc, ...val };
}, {});
}
const human = { name: "John", age: 37 };
const traits = { age: 29, hobby: "Programming computers" };
const attribute = { age: 40, nationality: "Belgian" };
const person = mergeObj(human, traits, attribute);
console.log(person);