Friday, 4 September 2015

Merge two json/javascript arrays in to one array

Merge two json/javascript arrays in to one array



(function($){$.concat||$.extend({concat:function(b,c){var a=[];for(var x in arguments)if(typeof a=='object')a=a.concat(arguments[x]);return a}});})(jQuery);

$(function() {
    var json1 = [{id:1, name: 'xxx'}],
        json2 = [{id:2, name: 'xyz'}],
        json3 = [{id:3, name: 'xyy'}],
        json4 = [{id:4, name: 'xzy'}],
        json5 = [{id:5, name: 'zxy'}];
   
    console.log($.concat(json1, json2, json3))
    console.log($.concat(json1, json2, json3, json4, json5))
    console.log($.concat(json4, json1, json2, json5))
});