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']
is he wrong I think it should output [12, 'ss', 'sdd', 'kk', '12'], is it possible to fix this promble?
source share