<!-- 数组去重:
1.便利原数组
2.判断新数组中是否有该元素(indexOf == -1) 没有则向新数组Push -->
<script>
var arr = [2, 3, 8, 6, 22, 33, 2, 6, 5, 7, 8, 15, , 2];
var newarr = new Array;
for (var i = 0; i < arr.length; i++) {
if (newarr.indexOf(arr[i]) == -1) {
newarr.push(arr[i]);
}
}
alert(newarr);
</script>
js数组去重
最新推荐文章于 2024-08-17 21:49:37 发布