Menu
I have this array with repeating elements (length 15):
`let arr = [6, 8, 9, 9, 80, 80, 87, 88, 88, 88, 89, 89, 90, 91, 932]
I want to remove all the duplicates, so wrote the following code:
“`
arr.filter((elem, index, arr) => {
if (arr[index] == arr[index+1]) {
arr.splice(index, 1)
}
})
After logging arr, I got:
“`
[
6, 8, 9, 80, 87,
88, 88, 89, 90, 91,
932
]
I can’t understand why I get 88 twice. This behaviour happens if an item is repeated more than twice. Any explanations/hints?