Size: 2513
Comment:
|
Size: 3249
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 6: | Line 6: |
||<tablewidth="796px" tableheight="123px"#cccccc>'''Function ''' ||<#cccccc>'''Type''' ||<#cccccc>'''Description '''||||<style="text-align:center"> || || | ||<tablewidth="796px" tableheight="123px"#cccccc>'''Function ''' ||<#cccccc>'''Type''' ||<#cccccc>'''Description ''' ||||<style="text-align:center"> || || |
Line 11: | Line 11: |
||[[#concat|concat]] ||array ||Used to join two or more arrays together. || ||[[#sort|sort]] ||array ||Used to sort the order of array elements. || |
|
Line 19: | Line 23: |
.myArray = ["a","b","c","d"] .echo "myArray = "+myArray .returnVal = myArray.push("e") .echo "myArray = "+myArray .echo "returnVal = "+returnVal |
. myArray = ["a","b","c","d"] . echo "myArray = "+myArray . returnVal = myArray.push("e") . echo "myArray = "+myArray . echo "returnVal = "+returnVal |
Line 26: | Line 31: |
.a,b,c,d .a,b,c,d,e .5 |
. a,b,c,d . a,b,c,d,e . 5 |
Line 36: | Line 42: |
.myArray = ["a","b","c","d"] .echo "myArray = "+myArray .returnVal = myArray.pop() .echo "myArray = "+myArray .echo "returnVal = "+returnVal |
. myArray = ["a","b","c","d"] . echo "myArray = "+myArray . returnVal = myArray.pop() . echo "myArray = "+myArray . echo "returnVal = "+returnVal |
Line 43: | Line 50: |
.a,b,c,d .a,b,c .d |
|
Line 47: | Line 51: |
. a,b,c,d . a,b,c . d |
|
Line 54: | Line 61: |
.myArray = ["a","b","c","d"] .echo "myArray = "+myArray .returnVal = myArray.unshift("_") .echo "myArray = "+myArray .echo "returnVal = "+returnVal |
. myArray = ["a","b","c","d"] . echo "myArray = "+myArray . returnVal = myArray.unshift("_") . echo "myArray = "+myArray . echo "returnVal = "+returnVal |
Line 61: | Line 69: |
.a,b,c,d ._,a,b,c,d .5 |
. a,b,c,d . _,a,b,c,d . 5 |
Line 71: | Line 80: |
.myArray = ["a","b","c","d"] .echo "myArray = "+myArray .returnVal = myArray.shift() .echo "myArray = "+myArray .echo "returnVal = "+returnVal |
. myArray = ["a","b","c","d"] . echo "myArray = "+myArray . returnVal = myArray.shift() . echo "myArray = "+myArray . echo "returnVal = "+returnVal |
Line 78: | Line 88: |
.a,b,c,d .b,c,d .a |
. a,b,c,d . b,c,d . a = concat = '''Usage:''' array.concat() 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 = sort = '''Usage:''' array.sort() Used to sort the order of array elements. '''Example:''' . array = ["b", "a", "d", "c"] . echo array.sort() '''Result:''' . a,b,c,d |
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 |
|
|
|
array |
Adds one or more elements to the end of an array and returns the new length of the array. |
||||
array |
Removes the last element from an array and returns the value of that element. |
||||
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. |
||||
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. |
||||
array |
Used to join two or more arrays together. |
||||
array |
Used to sort the order of array elements. |
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:
- myArray = ["a","b","c","d"]
- echo "myArray = "+myArray
- returnVal = myArray.push("e")
- echo "myArray = "+myArray
- echo "returnVal = "+returnVal
Result:
- a,b,c,d
- a,b,c,d,e
- 5
pop
Usage: array.pop()
Removes the last element from an array and returns the value of that element.
Example:
- myArray = ["a","b","c","d"]
- echo "myArray = "+myArray
- returnVal = myArray.pop()
- echo "myArray = "+myArray
- echo "returnVal = "+returnVal
Result:
- a,b,c,d
- a,b,c
- d
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:
- myArray = ["a","b","c","d"]
- echo "myArray = "+myArray
- returnVal = myArray.unshift("_")
- echo "myArray = "+myArray
- echo "returnVal = "+returnVal
Result:
- a,b,c,d
- _,a,b,c,d
- 5
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:
- myArray = ["a","b","c","d"]
- echo "myArray = "+myArray
- returnVal = myArray.shift()
- echo "myArray = "+myArray
- echo "returnVal = "+returnVal
Result:
- a,b,c,d
- b,c,d
- a
concat
Usage: array.concat()
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
sort
Usage: array.sort()
Used to sort the order of array elements.
Example:
- array = ["b", "a", "d", "c"]
- echo array.sort()
Result:
- a,b,c,d