js:写一个函数,实现数组[1,2,2,3,5,4,3,3,3,3,5,4,6,7,6,9,9,9,9]的去重
时间: 2023-11-09 09:09:49 浏览: 51
以下是实现数组去重的JS函数代码:
```javascript
function unique(arr){
var result = [];
for(var i=0; i<arr.length; i++){
if(result.indexOf(arr[i]) == -1){
result.push(arr[i]);
}
}
return result;
}
var arr = [1,2,2,3,5,4,3,3,3,3,5,4,6,7,6,9,9,9,9];
var newArr = unique(arr);
console.log(newArr);
```
阅读全文