标签:log == dex for style return adb splice var
第一种:
var arr=[1,2,3,4,5,3,4,5,6,2,‘hah‘,‘hah‘,‘a‘,‘b‘,‘a‘];
function fn(){
var na = [];
for(var i = 0; i < arr.length; i++){
if (na.indexOf(arr[i]) == -1){na.push(arr[i]);}
}
return na;
}console.log(fn());//输出=>1,2,3,4,5,6,‘hah‘,a,b
第二种:
var abc=[‘a‘,‘d‘,‘b‘,‘c‘,‘a‘,‘d‘]for(var i=0;i<abc.length;i++){
for(var j=i+1;j<abc.length;j++){
if(abc[i]==abc[j]){ abc.splice(j,1); j--;}
}
}console.log(abc);//结果=> adbc
标签:log == dex for style return adb splice var
原文地址:http://www.cnblogs.com/week-1/p/6536618.html