javascript - How to push elements of an object into another object? -
like in arrays can add new elements using array.push(item)
. how same objects
? , can done inside object? like:
var myobject={apple: "a", orange: "o"}; var anothobject = {lemon: "l", myobject};
you can use jquery's extend function: http://api.jquery.com/jquery.extend/
var object1 = { apple: 0, banana: { weight: 52, price: 100 }, cherry: 97 }; var object2 = { banana: { price: 200 }, durian: 100 }; // merge object2 object1 $.extend( object1, object2 );
Comments
Post a Comment