Array.filter()
过滤不符合条件的值。
let a = [1,1,1,2,2,3,2,1,3];
let r = a.filter((item, i) => a.indexOf(item) == i);
console.log(r);
// 数组项为对象的去重
let a = [
{index: 1},
{index: 1},
{index: 2},
{index: 2},
{index: 3},
{index: 1},
];
let r = a.filter((item, i) => a.findIndex(j => j.index == item.index) == i);
console.log(r);