Pro tip to remember .unshift() vs .shift()
In case anyone has trouble remember the difference between unshift and shift.
The way I remember it is that unshift is longer than shift, so unshift will make the array longer,
so we add to the front of the array.
And shift is shorter than unshift so it will shrink the array,
so you remove the item from the front of the array.
This applies for push / pop as well push is has more chars so it lengths the array,
so it adds element to end of the array and pop is shorter so it removes item from the end of the array.
Most people will remember push / pop since we use it so much and it's a little more intuitive,
with method name.
Hope this helps,
Cheers 🙂
8
2 comments
Ronald Paek
4
Pro tip to remember .unshift() vs .shift()
Developer Pro
skool.com/developerpro
Learn how to code. Make money. Have fun. Enjoy life.
Leaderboard (30-day)
powered by