Hello friends,
Most of time we need to create Object of contents in jQuery and use it according to requirement , So in this block you will see how to merge two or more object in first object .
When two or more object arguments are supplied to $.extend(), properties from all of the objects are added to the target object. Arguments that are null or undefined are ignored.
var object = $.extend({}, object1, object2);
Example:-
var object1 = {
apple: 0,
banana: { weight: 52, price: 100 },
cherry: 97
};
var object2 = {
banana: { price: 200 },
durian: 100
};
// Merge object2 into object1
$.extend( object1, object2 );
// Assuming JSON.stringify - not available in IE<8
$( "#log" ).append( JSON.stringify( object1 ) );
0 Comment(s)