Answer the question
In order to leave comments, you need to log in
How to remove an element from an array if it repeats the previous one?
There is an array in which different values \u200b\u200bare consecutive, how to remove the next value if it repeats the previous one?
Answer the question
In order to leave comments, you need to log in
Remove from existing array:
for (let i = arr.length; --i > 0; ) {
if (arr[i] === arr[i - 1]) {
arr.splice(i, 1);
}
}
arr.filter((n, i, a) => !i || a[i - 1] !== n)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question