|
Listing 5. Array's methods
> var myArray = ["Hello", 1, true]
> myArray[0]
"Hello"
> myArray.length
3
> myArray.pop()
true
> myArray
["Hello", 1]
> myArray.pop()
1
> myArray
["Hello"]
> myArray.push("pushed")
2
> myArray
["Hello", "pushed"]
You can obtain an Array's value via its position, which is zero-based. Arrays respond to push and pop, where push adds an item (at its last spot) and pop removes one (like a stack, from the last position).
Arrays also support iteration, shown in Listing 6: |
|