Written by Chris Walker
There is really just one property of arrays. You can measure their length. Their length is a tricky number. Since computers begin counting at the number zero, the first item in the array is the zeroth item. As a human you may say there are three things in an array. The length property will tell you that, but a computer starts counting at zero. This means that the position in the array are defined as 0, 1, and 2. So, you’ll run into a problem if you try to access the third item in an array with a length of 3.
There are a lot of methods on an array. These array methods include…
- unshift() Moves all items in an array and places new item first
- push() adds new items to end of an array
- pop() removes last item from an array
- indexOf() shows where first instance of a value is in the array
- lastIndexOf() shows where last instance of an value is located
- sort() sorts an array. This is permanent!
- reverse() switches order an array. This is permanent!
- concat() joins two arrays together
- toString() turns an array into a string with comas between values
- join() places values in a string but allows you to use a different character than commas
Go To An Older Location
Build A WordPress Theme From Scratch
Go To A Newer Location