// 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);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.