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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -