I am making an attempt at writing a function in JavaScript that accepts an array that has duplicates in it and returns the same array removing duplicates. I know how to this using a Set, filter and reduce but I wanted to try to do it without using those functions. The problem is that I don't know how to splice the duplicate item once I have found them, so how can I just remove the item from the array if it is found as a duplicate, here is my code:
function clearDuplicatesInArray(arr, item) {
for(i = 0; i < arr.length; i++) {
for(j = 0; j < arr.length; j++) {
if(arr[i] === arr[j]) {
arr.splice(arr[i], arr[j])
}
}
}
return arr;
}
clearDuplicatesInArray([1,1,2,3]);