DEV Community

loading...

Discussion on: How to remove duplicates from JavaScript array

Collapse
mahmoudibnsamy profile image
Mahmoud Ibn Samy

why did you use an instance of the numbers array, not the number array itself? " [...numbers].sort() not numbers.sort() "

Collapse
hi_iam_chris profile image
Kristijan Pajtasev Author

That is a good question, sort is a destructive function. This means running sort on numbers array will change original numbers array.

Thread Thread
mahmoudibnsamy profile image
Mahmoud Ibn Samy

wow I forgot that