2024年07月29日 建站教程
1、ES6判断数组是否存在重复元素
let arr = [1, 2, 3, 4, 5, 2, 3];
if ((new Set(arr)).size != arr.length) {
console.log('数组有重复值')
}
2、获取数组重复的元素
repeat(arr) {
var tmp = [];
if (Array.isArray(arr)) {
arr
.concat()
.sort()
.sort(function(a, b) {
if (a == b && tmp.indexOf(a) === -1) tmp.push(a);
});
}
return tmp;
},
想了解删除重复元素,请查看“最简单的js数组去重方法”
本文链接:http://so.lmcjl.com/news/9448/