Skip to main content

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(Object addElement)

Parameters:

ParamData typeDescription
addElementAny data typeThe 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(Number index)

Parameters:

ParamData typeDescription
indexNumberThe 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(Object searchElement)

Parameters:

ParamData typeDescription
searchElementAny data typeThe 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(Boolean isAscending)

Parameters:

ParamData typeDescription
isAscendingBooleanApplicable 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(List anotherList)

Parameters:

ParamData typeDescription
anotherListListThe 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(List removeListVariable)

Parameters:

ParamData typeDescription
removeListVariableListThe 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(); // 7

get#

The 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:

ParamData typeDescription
indexNumberThe 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

contains#

The 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:

ParamData typeDescription
searchElementAny data typeThe 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

set#

The set() function updates a specified value of a index in a list.

Syntax:

listVariable.set(Number index, Object element)

Parameters:

ParamData typeDescription
indexNumberThe index of the element which will be updated with a new value.
elementAny data typeThe 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(); // true

join#

The join() function takes delimeter as arguments. It returns string as output.

Syntax:

listVariable.join(String delimiter);

Parameters:

ParamData typeDescription
listVariableNumberThe list which have to be joined.
delimiterspecial_charactersThe 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

parse#

The 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"}]