How to merge Objects in JavaScript


We can merged two or more objects in JS using spread operator but it override the value with same key name.

let object1 = {name:'Vipin Katiyar',age:35};
let object2 = {name:'Umesh Yadav',gender:'Male'};
let merged_obj = {...object1,...object2};

console.log(merged_obj);
//Output : {name: "Umesh Yadav", age: 35, gender: "Male"}


Related

String Concatenation in JavaScript
Tag Template literals (Strings) in JavaScript
Destructuring assignment in JavaScript
Difference between null and undefined in JavaScript
localStorage, sessionStorage and cookies in JavaScript?