r/javascript • u/freebit • 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
38
u/senocular Mar 24 '18
I used the length to help remember.
pushis longer thanpopbecause it addspopis shorter thanpushbecause it removesunshiftis longer thanshiftbecause it addsshiftis shorter thanunshiftbecause it removesNot as fun as dropping the "f" tho :(