This question already has an answer here:
这个问题在这里已有答案:
- Remove duplicate element pairs from multidimensional array 7 answers
从多维数组7答案中删除重复的元素对
What is best way to filter 2d arr and return also 2d but with only unique arrays as elements: [[7,3,7],[7,7,3],[3,7,7],[3,7,7],[7,7,3],[7,3,7]]
should return [[7,3,7],[7,7,3],[3,7,7]]
?
什么是过滤2d arr并返回2d但只有唯一数组作为元素的最佳方法:[[7,3,7],[7,7,3],[3,7,7],[3,7, 7],[7,7,3],[7,3,7]应该返回[[7,3,7],[7,7,3],[3,7,7]]?
1 个解决方案
#1
0
Try this:
工作示例JSBin
var uniques = function(items) {
var map = {};
return items.filter(function(item) {
return item in map ? false : map[item] = true;
});
};
#1
0
Try this:
工作示例JSBin
var uniques = function(items) {
var map = {};
return items.filter(function(item) {
return item in map ? false : map[item] = true;
});
};