r/javascript • • Mar 24 '18

Can't keep Array.shift vs Array.unshift straight? (NSFW) NSFW

Here is a helpful, although gross mnemonic to help keep the two straight in your head. Drop the "f".

So, Array.shit() drops a load (element) from the beginning of an array and Array.unshit() will do the opposite.

69 Upvotes

31 comments sorted by

View all comments

38

u/senocular Mar 24 '18

I used the length to help remember.

push is longer than pop because it adds
pop is shorter than push because it removes
unshift is longer than shift because it adds
shift is shorter than unshift because it removes

Not as fun as dropping the "f" tho :(

3

u/tunnckoCore node-formidable, regexhq, jest, standard-release Mar 24 '18

Interesting.

2

u/frambot Mar 24 '18

This is super helpful, thank you!