<script>
var arr = [1,6,3,9,4,9,3,8,2]; var obj = {},newArr = []; function delRepeat(){ for(var i=0,j=arr.length;i<j;i++){ if(!obj[arr[i]]){ newArr.push(arr[i]); obj[arr[i]] = arr[i]; } } }delRepeat();//删掉重复项
console.log(newArr);//打印新数组 </script>本文共 298 字,大约阅读时间需要 1 分钟。
<script>
var arr = [1,6,3,9,4,9,3,8,2]; var obj = {},newArr = []; function delRepeat(){ for(var i=0,j=arr.length;i<j;i++){ if(!obj[arr[i]]){ newArr.push(arr[i]); obj[arr[i]] = arr[i]; } } }delRepeat();//删掉重复项
console.log(newArr);//打印新数组 </script>转载于:https://my.oschina.net/guoxin2014/blog/1537459