Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to merge the contents of two or more objects together into the first object using jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 199
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: