The following functions can be used to manipulate an array.

Click each function name in the table below for more details of it, with examples.

Functions

Function

Type

Description

push

array

Adds one or more elements to the end of an array and returns the new length of the array.

pop

array

Removes the last element from an array and returns the value of that element.

unshift

array

Adds one or more elements to the beginning of an array and returns the new length of the array. The other elements in the array are moved from their original position, i, to i+1.

shift

array

Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1.

concat

array

used to join two or more arrays together.

push

Usage: array.push("x")

Adds one or more elements to the end of an array and returns the new length of the array.

Example:

Result:

pop

Usage: array.pop()

Removes the last element from an array and returns the value of that element.

Example:

Result:

unshift

Usage: array.unshift("x")

Adds one or more elements to the beginning of an array and returns the new length of the array. The other elements in the array are moved from their original position, i, to i+1.

Example:

Result:

shift

Usage: array.shift()

Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1.

Example:

Result:

concat

Usage: array123 = array1.concat(array2,array3)

used to join two or more arrays together.

Example:

boy = ["Luke", "Bob","Jason"]

girl = ["Emma", "Katie", "Chiara"]

uni = ["Jordan","alex","Jessie"]

names = uni.concat(girl,boy)

echo names

Result:

Jordan,alex,Jessie,Emma,Katie,Chiara,Luke,Bob,Jason


CategoryFunctions

Arrays (last edited 2014-07-28 23:25:16 by LKD70)