我的情景是:
var a=[{name:"Rambabu",id:"101"},{name:"Divya",id:"102"}];
var b=[{name:"manu",id:"103"},{name:"sudha",id:"104"}];
var c= a array + b array data objects.
预期产出:
c= [{name:"Rambabu",id:"101"},{name:"Divya",id:"102"},{name:"manu",id:"103"},{name:"sudha",id:"104"}]
答案 0 :(得分:2)
使用.concat
var a=[{name:"Rambabu",id:"101"},{name:"Divya",id:"102"}];
var b=[{name:"manu",id:"103"},{name:"sudha",id:"104"}];
var c = a.concat(b);
console.log(c);
或者您也可以使用点差运算符...
var a=[{name:"Rambabu",id:"101"},{name:"Divya",id:"102"}];
var b=[{name:"manu",id:"103"},{name:"sudha",id:"104"}];
var c = [...a, ...b];
console.log(c);