JS Array hax: Push Pop Shift and Unshift
These incredibly useful array methods are often overlooked and under utilized. When used properly, if for some reason you need to change your code from appending an array to pre-pending it, you just change from push() to unshift(). It should take all of two seconds. Without using these functions you'll end up writing 10 lines or so that are SOOOOOO boring you'll want to barf. Here's a quick reference of what they do: push() - add element to the end of the array pop() - remove and return the element at the end shift() - remove and return the element at the beginning unshift() - add element to the beginning of the array pushing the others down 1 Shift and unshift seem to me to save the most time.
0 Comments:
Post a Comment
<< Home