合并a,b的json,并且以b覆盖a的同类项
function joinJson(a,b) {
var c = {};
for(var key in a){
if(b[key]){
if(Object.prototype.toString.call(b[key]) === "[object Array]" || Object.prototype.toString.call(b[key])==='[object Object]'){
c[key] = joinJson(a[key],b[key]);
}else {
c[key] = b[key];
console.log(c[key])
}
}
}
return {
...a,
...b,
...c,
};
}
网友评论