APIs
This page provides API specifications of array.
Properties
.length
Return the number of elements in an array.
Example
Get length of an array
var nums = [1, 2, 3, 4]
puts nums.length // 4Get the last element in array
var arrOS = ['Windows', 'Linux', 'OSX']
puts arrOS[arrOS.length] // OSXIterate through an array
var arr = [2, 4, 8, 10]
for i = 0, arr.length - 1 {
puts arr[i]
}Methods
.push(value)
Push value to an array
Parameters (1)
value : any
A value to be pushed
Return value
This method return the index of last pushed value in array.
.pop()
Remove the last element of array
Parameters (0)
Return value
The last element of array.
.shift()
Remove the first element of array.
Parameters (0)
Return value
The first element of array.
Last updated
Was this helpful?