两个json数组合并 去除重复的数据

var a=[{"id":"001","name":"小二","age":"18","address":"北京市1","school":"1"},{"id":"002","name":"李四","age":"15","address":"北京市2","school":"2"},{"id":"003","name":"王五","age":"16","address":"北京市3","school":"4"}];
var b=[{"id":"004","name":"小明","age":"18","address":"北京市3","school":"1"},{"id":"003","name":"王五","age":"16","address":"北京市4","school":"4"}]
var c = a.concat(b); //合并数组
 var temp = {}; //存放id
   var result = []; //新数组
   c.map((item,index) => {
       if(!temp[item.id]){
           result.push(item);
           temp[item.id] = true;
       }
   })

你可能感兴趣的:(jquery,js)