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']
does it make wrong?I think it should output [12,'ss','sdd','kk','12'],can we fixed this promble?
var i=0should be a semicolon.