List functions
#
addThe add() function takes listVariable and addElement as arguments, and adds the specified element(addElement) to the list variable(listVariable).
Syntax:
listVariable
.add(Object
addElement)
Parameters:
Param | Data type | Description |
---|---|---|
addElement | Any data type | The element to be added to the list. |
Returns: Void
Example:
listVariable = [];listVariable.add(10);listVariable.add("string");listVariable.add(true);
log listVariable; // [10, "string", true]
#
removeThe remove() function removes the element in the specified indexValue from the list
Note: Index starts from 0.
Syntax:
listVariable
.remove(Number
index)
Parameters:
Param | Data type | Description |
---|---|---|
index | Number | The index of the element which will be removed from the list, and returned. |
Returns: List
Example:
listVariable = [1, 2, 3, 4, 5];listVariable.remove(1);
log listVariable; // [1, 3, 4, 5]
#
removeElementThe removeElement() function takes listVariable and searchElement as arguments, and removes the searchElement from listVariable.
Syntax:
listVariable
.removeElement(Object
searchElement)
Parameters:
Param | Data type | Description |
---|---|---|
searchElement | Any data type | The element to be removed from the list. |
Returns: Void
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory"];listVariable.removeElement("Asset");
log listVariable; // ["Work Order", "FDD", "Inventory"];
#
clearThe clear() function removes all elements from the list.
Syntax:
listVariable
.clear()
Returns: Void
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory"];listVariable.clear();
log listVariable; // [];
#
sortThe sort() function takes listVariable and isAscending as arguments and returns the sorted list.
- ascending order if the specified isAscending is true.
- ascending order if the isAscending is not specified.
- descending order if the specified isAscending is false.
Syntax:
listVariable
.sort(Boolean
isAscending)
Parameters:
Param | Data type | Description |
---|---|---|
isAscending | Boolean | Applicable values are: true or false. |
Returns: List
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory"];sortedListVariable = listVariable.sort();
log sortedListVariable; // ["Asset", "FDD", "Inventory", "Work Order"];
#
addAllThe addAll() function takes listVariable and anotherList as arguments, and adds all elements present in anotherList to listVariable.
Syntax:
listVariable
.addAll(List
anotherList)
Parameters:
Param | Data type | Description |
---|---|---|
anotherList | List | The list variable whose elements will be added. |
Returns: Void
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory"];anotherList = ["Visitor", "Vendor", "Tenant"];listVariable.addAll(anotherList);
log listVariable; // ["Work Order", "Asset", "FDD", "Inventory", "Visitor", "Vendor", "Tenant"]
#
removeAllThe removeAll() function takes listVariable and removeListVariable as arguments. It removes the elements present in removeListVariable from listVariable.
Syntax:
listVariable
.removeAll(List
removeListVariable)
Parameters:
Param | Data type | Description |
---|---|---|
removeListVariable | List | The elements present in this list will be removed from listVariable. |
Returns: Void
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory", "Visitor", "Vendor", "Tenant"];removeListVariable = ["Visitor", "Vendor", "Tenant"];listVariable.removeAll(removeListVariable);
log listVariable; // ["Work Order", "Asset", "FDD", "Inventory"]
#
sizeThe size() function takes a listVariable as argument, and returns the count of elements in that list.
Syntax:
listVariable
.size()
Returns: Number
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory", "Visitor", "Vendor", "Tenant"];
log listVariable.size(); // 7
#
getThe get() function takes listVariable and indexValue as arguments. It returns the element present in the specified index in the list.
Syntax:
listVariable
.get(Number
index)
Parameters:
Param | Data type | Description |
---|---|---|
index | Number | The index of the element which will be returned. |
Returns: The return type will depend on the data type of the returned element.
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory", "Visitor", "Vendor", "Tenant"];
log listVariable.get(3); // Inventory
#
containsThe contains() function takes listVariable and searchElement as arguments. It returns true if listVariable contains the searchElement. Otherwise, returns false.
Syntax:
listVariable
.contains(Object
searchElement)
Parameters:
Param | Data type | Description |
---|---|---|
searchElement | Any data type | The element to be searched for in the list variable. |
Returns: Boolean
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory", "Visitor", "Vendor", "Tenant"];
log listVariable.contains("Visitor"); // true
log listVariable.contains("Rooms"); // false
#
setThe set() function updates a specified value of a index in a list.
Syntax:
listVariable
.set(Number
index,Object
element)
Parameters:
Param | Data type | Description |
---|---|---|
index | Number | The index of the element which will be updated with a new value. |
element | Any data type | The value which will replace the existing value. |
Returns: Void
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory", "Visitor", "Vendor", "Tenant"];listVariable.set(2, "Alarms");
log listVariable; // ["Work Order", "Asset", "Alarms", "Inventory", "Visitor", "Vendor", "Tenant"]
#
allMatchThe allMatch() function takes listVariable as arguments. It returns true if all the elements are same. Otherwise, returns false.
Syntax:
listVariable
.allMatch()
Returns: Boolean
Example:
listVariable = [100, 100, 100];
log listVariable.allMatch(); // true
#
joinThe join() function takes delimeter as arguments. It returns string as output.
Syntax:
listVariable.join(
String
delimiter);
Parameters:
Param | Data type | Description |
---|---|---|
listVariable | Number | The list which have to be joined. |
delimiter | special_characters | The seperator for joining each elements in the list.Note if not given by default it will be "," |
Returns: String
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory", "Visitor", "Vendor", "Tenant"];log listVariable.join("");//Work OrderAssetFDDInventoryVisitorVendorTenant
#
parseThe parse() function takes a JSON formatted text as an argument, and returns a jsonArray list object.
Syntax:
new NameSpace("list").parse(
String
jsonString);
Returns: list
Example:
data="[{\"A\":\"a\",\"B\":\"b\",\"C\":\"c\",\"D\":\"d\",\"E\":\"e\",\"F\":\"f\",\"G\":\"g\"}]";newlist=new NameSpace("list").parse(data);log newlist; //[{"A":"a","B":"b","C":"c","D":"d","E":"e","F":"f","G":"g"}]