- 09 Feb 2022
- 3 Minutes to read
- Print
- DarkLight
Array Actions
- Updated on 09 Feb 2022
- 3 Minutes to read
- Print
- DarkLight
Array Actions
appendArrayItem
Append an item to an array.
Property | Value | Description |
array* | expression, variable | the array |
item* | text, expression, variable | the item to append |
myArray = createArray()
appendArrayItem(myArray,"banana")
# Should return 1
log(myArray.length)
appendArrayItems
Append an array to an array.
Property | Value | Description |
destArray* | expression, variable | the array to append to |
srcArray* | expression, variable | the array to append |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
# Should return 3
log(myArray.length)
arrayContains
Check if an array contains a value.
Property | Value | Description |
array* | expression, variable | the array |
value* | text, expression, variable | the value to match |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItem(myArray,"banana")
# Should return true
hasBanana = arrayContains(myArray, "banana")
# Should return false
hasApple = arrayContains(myArray, "apple")
copyArray
Make a copy of an array.
Property | Value | Description |
array* | expression, variable | the array to copy |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
newArray = copyArray(myArray)
# Should return "banana"
log(newArray[1]) myArray = createArray(10)
# Should return 10
log(myArray.length)
createArray
Create an array.
Property | Value | Description |
size | expression, variable | initial size of the array - (default: 0) |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray(10)
# Should return 10
log(myArray.length)
getArrayItem
Get an array item.
Property | Value | Description |
array* | expression, variable | the array |
index* | expression, variable | the index of the item to get |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
myItem = getArrayItem(myArray,1)
# Should return "banana"
log(myItem)
getArraySize
Get the size of an array.
Property | Value | Description |
array* | expression, variable | the array |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
numItems = getArraySize(myArray)
# Should return 3
log(numItems)
insertArrayItem
Insert an array item.
Property | Value | Description |
array* | expression, variable | the array |
index* | expression, variable | the index in the array to insert the item |
item* | text, expression, variable | the item |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
insertArrayItem(myArray,2,"plum")
# Should return "apple,banana,plum,pear"
log(myArray)
insertArrayItems
Insert items from one array into another array.
Property | Value | Description |
destArray* | expression, variable | the array to insert into |
index* | expression, variable | the index in destArray to insert the srcArray |
srcArray* | expression, variable | the array to insert |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
insertArrayItems(myArray,1,["orange","grapes"])
# Should return "apple,orange,grapes,banana,pear"
log(myArray)
joinArray
Join the values of the items in an array into a string.
Property | Value | Description |
array* | expression, variable | the array |
delimiter | text, expression, variable | the delimeter to inject in between the items in the string (default: none) |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
myString = joinArray(myArray,"::")
# Should return "apple::banana::pear"
log(myString)
removeArrayItem
Remove and return an item from an array.
Property | Value | Description |
array* | expression, variable | the array |
index* | expression, variable | the index of the item to remove |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
removedItem = removeArrayItem(myArray,1)
# Should return "apple,pear"
log(myArray)
# Should return "banana"
log(removedItem)
removeArrayItems
Remove and return items from an array.
Property | Value | Description |
array* | expression, variable | the array |
index* | expression, variable | the starting index of the items to remove |
count* | expression, variable | the number of items to remove |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear","grapes","coconut"])
removedItems = removeArrayItems(myArray,1,2)
# Should return "apple,grapes,coconut"
log(myArray)
# Should return "banana,pear"
log(removedItems)
removeLastArrayItem
Remove and return the last item from an array.
Property | Value | Description |
array* | expression, variable | the array to remove the last item from |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear","grapes","coconut"])
removedItem = removeLastArrayItem(myArray)
# Should return "apple,banana,pear,grapes"
log(myArray)
# Should return "coconut"
log(removedItem)
reverseArray
Reverse the order of the items in an array.
Property | Value | Description |
array* | expression, variable | the array to reverse |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear","grapes"])
reverseArray(myArray)
# Should return "grapes,pear,banana,apple"
log(myArray)
setArrayItem
Set array item.
Property | Value | Description |
array* | expression, variable | the array |
index* | expression, variable | the index of the item to set |
item* | text, expression, variable | the item |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
setArrayItem(myArray,2,"plum")
# Should return "apple,banana,plum"
log(myArray)
setArraySize
Set the size of an array.
Property | Value | Description |
array* | expression, variable | the array |
size* | expression, variable | the new size |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear"])
setArraySize(myArray,1)
# Should return "apple"
log(myArray)
sliceArray
Create a new array from a subset of the items in an array.
Property | Value | Description |
array* | expression, variable | the original array |
index* | expression, variable | the starting index of the items to be put in the new array |
count* | expression, variable | the number of items to put into the new array |
returnVariable | expression, variable | name of the variable to be assigned to the return value |
myArray = createArray()
appendArrayItems(myArray,["apple","banana","pear","grapes"])
newArray = sliceArray(myArray,0,2)
# Should return "apple,banana,pear,grapes"
log(myArray)
# Should return "apple,banana"
log(newArray)
sortArray
Sort an array.
Property | Value | Description |
array* | expression, variable | the array to sort |
ignoreCase | boolean, expression, variable | ignore case when comparing items (default: false) |
descending | boolean, expression, variable | sort in descending order (default: false) |
keyFields | text, expression, variable | comma separated list of fields or properties to sort on (default: sort based on the string value of each item) |
myArray = createArray()
appendArrayItems(myArray,["apple","pear","grapes","banana"])
sortArray(myArray)
# Should return "apple,banana,grapes,pear"
log(myArray)