日期:2014-05-16 浏览次数:20442 次
function dist(){ var s = ["a","ba","a","c"]; var arr = [], map = {}; for(var i=0; i<s.length; i++){ var n = s[i]; if(!map.hasOwnProperty(n)){ map[n] = true; arr.push(n); } } alert(arr); } function dist1(){ var array=[2.3,2.3,"a","b","b",true,true,true,false,1,0,undefined,null]; for(var i=0;i<array.length;i++){ for(var j=i+1;j<array.length;j++){ if(array[j]===array[i]) { array.splice(j,1); j--; } } } alert(array); }