Home Article JS实现数组去重(重复的元素只保留一个)

JS实现数组去重(重复的元素只保留一个)

Release time:2020-09-30 22:37:52 Author:admin Reading volume:2916
var arr=[2,8,5,0,5,2,6,7,2];
function unique1(arr){
  var hash=[];
  for (var i = 0; i < arr.length; i++) {
     if(hash.indexOf(arr[i])==-1){
      hash.push(arr[i]);
     }
  }
  return hash;
}
  
I want to comment
Leave a message
http://www.151600.com/index.php/
User login
You have not written any reviews yet!
You have commented!
Can only praise once!
You have a collection!