Merge JavaScript objects with jQuery 

Joined:
02/21/2009
Posts:
172

June 17, 2014 16:13:40    Last update: June 17, 2014 16:13:40
The jQuery extend function merges the contents of two or more objects into the first one.
// initialize the first object
o1 = { a: 1, b: 2, c: 3 }

// initialize the second object 
o2 = { d: 4, e: 5}

// merge o2 into o1, o1 is returned
jQuery.extend(o1, o2) // returns: { a: 1, b: 2, c: 3, d: 4, e: 5 }

// o1 is altered
o1 == { a: 1, b: 2, c: 3, d: 4, e: 5 }
Share |
| Comment  | Tags