如何将两个json合并成一个

时间:2022-08-06 22:16:50
//调用方法:
var targetObject = [{name:"11",age:11}];
var sourceObject = [{name:"22",age:22}];
var result = $.extend(true,targetObject,sourceObject);

//手写拼接:
var str1=[{name:"11",age:11}];
var str2=[{name:"22",age:22}];
 
var str3 = [];
 
for (var i = 0; i < str1.length; i++) {
    str3.push(str1[i]);
}
 
for (var i = 0; i < str2.length; i++) {
    str3.push(str2[i]);
}
 
--------------
 
var str3 = str1.concat(str2);