Murtaza Khursheed Hussain Murtaza Khursheed Hussain - 1 year ago 49
jQuery Question

Merge two json/javascript arrays in to one array

I have two json arrays like

var json1 = [{id:1, name: 'xxx' ...}]
var json2 = [{id:2, name: 'xyz' ...}]


I want them merge in to single arrays

var finalObj = [{id:1, name: 'xxx' ...},{id:2, name: 'xyz' ...}]


Regards

Answer Source

You want the concat method.

var finalObj = json1.concat(json2);