且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从阵列中完全删除重复的项目

更新时间:2022-06-20 02:57:11

你可以使用 Array#filter Array #indexOf Array#lastIndexOf 并仅返回共享相同索引的值。

You could use Array#filter with Array#indexOf and Array#lastIndexOf and return only the values which share the same index.

var array = [1, 2, 3, 4, 4, 5, 5],
    result = array.filter(function (a, _, aa) {
        return aa.indexOf(a) === aa.lastIndexOf(a);
    });

console.log(result);