DEV Community

Discussion on: Arrays, any way you slice it

Collapse
 
tiberiucorbu profile image
Tiberiu CORBU

Nice article. I have just a little addition, negative slice cuts from the end:

[0, 1, 2, 3, 4].slice(-2) // => [3, 4]

and slice returns a copy and does not mutate the initial array like some other function do.

Collapse
 
terabytetiger profile image
Tyler V. (he/him)

Good points, I really should have explained that slice doesn't mutate!