List functions
add#
The add() function takes listVariable and addElement as arguments, and adds the specified element(addElement) to the list variable(listVariable).
Syntax:
listVariable.add(ObjectaddElement)
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]remove#
The remove() function removes the element in the specified indexValue from the list
Note: Index starts from 0.
Syntax:
listVariable.remove(Numberindex)
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]removeElement#
The removeElement() function takes listVariable and searchElement as arguments, and removes the searchElement from listVariable.
Syntax:
listVariable.removeElement(ObjectsearchElement)
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"];clear#
The clear() function removes all elements from the list.
Syntax:
listVariable.clear()
Returns: Void
Example:
listVariable = ["Work Order", "Asset", "FDD", "Inventory"];listVariable.clear();
log listVariable; // [];sort#
The 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(BooleanisAscending)
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"];addAll#
The addAll() function takes listVariable and anotherList as arguments, and adds all elements present in anotherList to listVariable.
Syntax:
listVariable.addAll(ListanotherList)
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"]removeAll#
The removeAll() function takes listVariable and removeListVariable as arguments. It removes the elements present in removeListVariable from listVariable.
Syntax:
listVariable.removeAll(ListremoveListVariable)
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"]size#
The 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(); // 7get#
The get() function takes listVariable and indexValue as arguments. It returns the element present in the specified index in the list.
Syntax:
listVariable.get(Numberindex)
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); // Inventorycontains#
The contains() function takes listVariable and searchElement as arguments. It returns true if listVariable contains the searchElement. Otherwise, returns false.
Syntax:
listVariable.contains(ObjectsearchElement)
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"); // falseset#
The set() function updates a specified value of a index in a list.
Syntax:
listVariable.set(Numberindex,Objectelement)
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"]allMatch#
The 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(); // truejoin#
The join() function takes delimeter as arguments. It returns string as output.
Syntax:
listVariable.join(
Stringdelimiter);
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 OrderAssetFDDInventoryVisitorVendorTenantparse#
The parse() function takes a JSON formatted text as an argument, and returns a jsonArray list object.
Syntax:
new NameSpace("list").parse(
StringjsonString);
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"}]