Javascript - 删除数组上的元素

时间:2017-06-07 07:45:31

标签: javascript

我有两组不同的数据,到目前为止,这就是我所做的



var data1 = [{
  name: "one",
  index: 1
}, {
  name: "two",
  index: 2
}, {
  name: "three",
  index: 3
}, {
  name: "four",
  index: 4
}, {
  name: "five",
  index: 5
}]

var data2 = [{
  name: "one",
  index: 1
}, {
  name: "two",
  index: 2
}]

var mappeddata2 = data2.map((item) => {
  return item.index
})


for (var a = 0; a < data2.length; a++) {
  console.log("console log", data1.filter((item) => {
    return item.index !== mappeddata2[a]
  }))
}
&#13;
&#13;
&#13;

我想要的是将data1与data2区分开来,结果应该是这样的

[{name: "three", index: 3},{name: "four", index: 4},{name: "five", index: 5}]

提前谢谢。

0 个答案:

没有答案