比较两个数组并合并而不重复

var a = [{id: 14679333, name: "Churchill Downs", eventStatusCode: "A", isActive: "true"},
         {id: 14679333, name: "Gulfstream", eventStatusCode: "A", isActive: "true"},
         {id: 14679333, name: "Remington Park", eventStatusCode: "A", isActive: "true"},
         {id: 14679333, name: "Santa Anita", eventStatusCode: "A", isActive: "true"}, 
         {id: 14679333, name: "Golden Gate Fields", eventStatusCode: "A", isActive: "true"}]


var b = [{id: 14679333, name: "Santa Anita", eventStatusCode: "A", isActive: "true"},
         {id: 14679333, name: "Charles Town", eventStatusCode: "A", isActive: "true"},
         {id: 14679333, name: "Golden Gate Fields", eventStatusCode: "A", isActive: "true"},
         {id: 14679333, name: "Remington Park", eventStatusCode: "A", isActive: "true"},
         {id: 14679333, name: "Los Alamitos", eventStatusCode: "A", isActive: "true"}]

码:

 for(var i=0; i< b.length;i++){
   if((b[i].typeName || b[i].name) != (a[i].typeName || a[i].name)){
    var c= a.concat(b)
     console.log("after concat",c)
   }
 }

我正在尝试比较两个数组并合并成没有重复的单个数组,但是我得到了以下输出:

c= [{id: 14679333, name: "Churchill Downs", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Gulfstream", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Remington Park", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Santa Anita", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Golden Gate Fields", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Santa Anita", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Charles Town", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Golden Gate Fields", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Remington Park", eventStatusCode: "A", isActive: "true"},
{id: 14679333, name: "Los Alamitos", eventStatusCode: "A", isActive: "true"}]

预期产量:

c = [{id: 14679333, name: "Churchill Downs", eventStatusCode: "A", isActive: "true"},
     {id: 14679333, name: "Gulfstream", eventStatusCode: "A", isActive: "true"},
     {id: 14679333, name: "Remington Park", eventStatusCode: "A", isActive: "true"},
     {id: 14679333, name: "Santa Anita", eventStatusCode: "A", isActive: "true"},
     {id: 14679333, name: "Golden Gate Fields", eventStatusCode: "A", isActive: "true"},
     {id: 14679333, name: "Charles Town", eventStatusCode: "A", isActive: "true"},
     {id: 14679333, name: "Los Alamitos", eventStatusCode: "A", isActive: "true"}]
评论