DEV Community

Discussion on: How to remove duplicates from JavaScript array

Collapse
 
ibnsamy96 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

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

Thread Thread
 
ibnsamy96 profile image
Mahmoud Ibn Samy

wow I forgot that