How to extend json object with jquery extension?

var dataset = {"read_data":[{"date":"2010\/11\/02 03:30:05","value":"2"}, {"date":"2010\/11\/02 03:30:06","value":"1"}]}; var append = {"read_data":[{"date":"2010\/11\/02 03:30:07","value":"3"}, {"date":"2010\/11\/02 03:30:08","value":"4"}]}; 

I have two data objects like these two. How to use JQuery.extend(); to unite them? so that they look so that:

 dataset === {"read_data":[{"date":"2010\/11\/02 03:30:05","value":"2"}, {"date":"2010\/11\/02 03:30:06","value":"1"}, {"date":"2010\/11\/02 03:30:07","value":"3"}, {"date":"2010\/11\/02 03:30:08","value":"4"}]}; 

All methods contained on this site do not work at all.

+4
source share
1 answer

jQuery.extend overwrites members with the same name and does not support merging arrays. You will need to do:

 $.merge(dataset.read_data, append.read_data); 
+7
source

All Articles