var arr1 =[1,2,2,2,3,3,3,4,5,6],
arr2 = [];
for(var i = 0,len = arr1.length; i< len; i++){
if(arr2.indexOf(arr1[i]) < 0){ //利用在arr2中查找不到arr1[i]的元素,会返回-1
arr2.push(arr1[i]);
}
}
console.log(arr2); //[ 1, 2, 3, 4, 5, 6 ]
删除一个数组中重复的元素
最新推荐文章于 2024-03-12 17:36:45 发布