I wrote a function in javaScript that checks if it is the first time the numbers has been seem, if so, it will be added to the the array. For some reason the first number is always repeating it, Ex:
if we pass [1,1,1,2,3,3,4,5] it will print out [1,1,2,3,4,5] instead of [1,2,3,4,5]
Could anyone tell me what I'm missing ?? Thank you in advance.
var numbers = [1,1,1,1,1,2,3,4,4,4,5,5,6,6,6,8];
function eliminateDup(arr){
var myArr = [];
for(var i = 0;i<arr.length;i++){
if(!myArr[arr[i]]){
myArr.push(arr[i]);
}
}
return myArr;
}
console.log(eliminateDup(numbers));