Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
组合两个Javascript对象_Javascript_Jquery - Fatal编程技术网

组合两个Javascript对象

组合两个Javascript对象,javascript,jquery,Javascript,Jquery,我有两个目标 var data = {property: [ {id: "1", name: "Snatch", type: "crime"}, {id: "2", name: "Witches of Eastwick", type: "comedy"}, {id: "3", name: "X-Men", type: "action"}, {id: "4", name: "Ordinary People", type: "drama"}, {id: "5", name: "B

我有两个目标

var data = {property: [
  {id: "1", name: "Snatch", type: "crime"},
  {id: "2", name: "Witches of Eastwick", type: "comedy"},
  {id: "3", name: "X-Men", type: "action"},
  {id: "4", name: "Ordinary People", type: "drama"},
  {id: "5", name: "Billy Elliot", type: "drama"},
  {id: "6", name: "Toy Story", type: "children"}
]};

我可以使用jquery或javascript将两者结合起来吗

var data = {property: [
  {id: "1", name: "Snatch", type: "crime"},
  {id: "2", name: "Witches of Eastwick", type: "comedy"},
  {id: "3", name: "X-Men", type: "action"},
  {id: "4", name: "Ordinary People", type: "drama"},
  {id: "5", name: "Billy Elliot", type: "drama"},
  {id: "6", name: "Toy Story", type: "children"},
  {id: "7", name: "Snatch", type: "crime"},
  {id: "8", name: "Witches of Eastwick", type: "comedy"}
]};
我尝试过使用推送功能,但没有成功

如何:

var data = {property: []}

var data2 = {property: []}

data.property =data.property.concat(data2.property);

使用阵列的
concat
功能,您可以加入它们。

concat是一种解决方案,但也会处理任何重复项

var data3 = _.union(data.property, data2.property)

这里根本没有JSON。您有JavaScript对象……而您正试图组合的是数组。
var data3 = _.union(data.property, data2.property)