How To Remove Duplicates From an Array in JavaScript

preview_player
Показать описание
Removing duplicates from an array in JavaScript can be done in many ways. In this short video, I'll show you 2 techniques - using the Set data structure and the array filter method.

For your reference, check this out:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

#dcode #javascript
Рекомендации по теме
Комментарии
Автор

Nice, I didnt know that second solution.

patrykkowalski
Автор

👏👌🙏🖖Excellent... BUT... what if the elements of the array are objects.. e.g. [{x:10, y:30, w:100, h:40}, {x:100, y:100, w:50, h:60}, {x:10, y:30, w:100, h:40}]?

suelingsusu
Автор

Is this the winning lotto numbers as well?

smoothbeak
Автор

Good stuff… which is the most performant?

m
Автор

Now can you do the same for complex array ? Like an array of objects ? :D

LudovicFontaine-lbcy
Автор

That's the first example that chat GPT will give you
or you can go the long way and do this
let arrayWithDuplicates = [1, 2, 3, 4, 1, 2, 5];
let uniqueArray = [];
=> {
if (uniqueArray.indexOf(value) === -1) {
uniqueArray.push(value);
}
});
console.log(uniqueArray);

igorr