4
var arr1 = [12,'ss','sdd','sdd','kk'];
function unique(array){
var o = {},b = [];
for(var i=0;i<array.length;i++){
if(!o[array[i]]){
b.push(array[i]);
o[array[i]] = true;
}
}
return b;
}
unique(arr1) //It works fine .output [12,'ss','sdd','kk']
but,it has some issues on arr2 below:
var arr2 = [12,'ss','sdd','sdd','kk','12'];//output [12,'ss','sdd','kk']
它是否出錯?我認爲應該輸出[12,'ss','sdd','kk','12'],我們可以修復這個問題嗎?關於Javascript Array獨特
逗號變種後`I = 0`應該是分號。 – 2011-12-17 10:12:43
我已經修復了分號。 – 2011-12-17 10:17:46