输入:
var b= [{
"cat_id": "1",
"cat_name": "teaching"
}];
var a= [ {
"username": "r",
"password": "r"
}];
我想要这样的输出
[{"username":"r","password":"r","cat_id":"1","cat_name":"teaching"}]
答案 0 :(得分:2)
您可以使用Object.assign()
扩展语法。
var b = [{"cat_id": "1","cat_name": "teaching"}];
var a = [{"username": "r","password": "r"}];
var result = [Object.assign({}, ...a, ...b)]
console.log(result)

答案 1 :(得分:1)
使用Object.assign
的可能解决方案。
var b = [{"cat_id":"1","cat_name":"teaching"}], a = [{"username":"r","password":"r"}],
res2 = [Object.assign({}, ...a.concat(b))];
console.log(res2);

答案 2 :(得分:0)
您可以使用扩展功能合并对象
$.extend( a, b);