JSFiddle - React, Tailwind, and code Playground

by Alexandre Simoes

JavaScript

// create two objects
var obj1 = { a:1, b:2, c:3 };
var obj2 = { b:40, d: 50};

// We'll be merging obj2 into obj1
// They have one property in common, property b
//   and obj2 has an additional property, property d
// The merge result will be: {a: 1, b: 40, c: 3, d: 50}

// Option1: create a new object based on the merge of obj1 and obj2
// This if particularly useful if you don't want to change any of the objects
var non_modify_merge = $.extend({}, obj1, obj2);

// Option 2: extend obj1 by merging it with obj2
// This will make obj1 the destination of the merge
var modify_merge = $.extend(obj1, obj2);

// display results in the console
// expected: {a: 1, b: 40, c: 3, d: 50}
console.log(non_modify_merge);
console.log(modify_merge);
console.log(obj1);