Duplicates Removal Using IndexOf in JS
Duplicates Removal Using IndexOf in JS
by SriSri M
JavaScript
var arrayN = [1,1,2,2,3,3,5];
var x,y, check;
var tempArr = [];
var unique = [];
for(x=0;x < arrayN.length; x++) {
tempArr.push(arrayN[x]);
check = true;
for(y=0;y < tempArr.length; y++) {
if(unique[y] == tempArr[x]) {
check = false;
}
}
if(check) {
unique.push(tempArr[x]);
}
/* if(unique.indexOf(tempArr[x]) < 0) {
unique.push(tempArr[x]);
} */
}
/* for(var i =0; i < ar.length; i++){
if(dist.indexOf(arr[i]) == -1) {
dist.push(arr[i]);
}
} */
console.log(unique);