DEV Community

Discussion on: TypeOf Array is Gotcha!

Collapse
 
hi_artem profile image
Artem

For me one of the recent things was sort() method of the Array object:

[3,100,20].sort() //outputs [ 100, 20, 3 ]

I had no idea it sorts them as string literals.

Collapse
 
qm3ster profile image
Mihail Malo

The other gotcha is that it mutates the source array, and then also returns it, unlike most Array.prototype methods.