如果要在Javascript中合并2个对象数组。你可以使用这一招
Array.prototype.push.apply(arr1,arr2);
例如
var arr1 = [{name: "lang", value: "English"},{name: "age", value: "18"}];var arr2 = [{name : "childs", value: '5'}, {name: "lang", value: "German"}];Array.prototype.push.apply(arr1,arr2); console.log(arr1); // final merged result will be in arr1
输出:
[{"name":"lang","value":"English"},{"name":"age","value":"18"},{"name":"childs","value":"5"},{"name":"lang","value":"German"}]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)