Skip to main content

Map functions

put#

The put() function takes key and value as arguments, and adds the key-value pair to the mapVariable.

Syntax:

mapVariable.put(String key, Object value);

Parameters:

ParamData typeDescription
keystringThe key to be added to the map.
ValuestringThe value to be added to the map.

Returns: Void

Example:

key = "name";value = "Facilio";
mapObject = {};mapObject.put(key, value);
log mapObject; // { name: "Facilio" }

putAll#

The putAll() function takes mapVariableOne and mapVariableTwo as arguments, and adds all key-value pairs present in mapVariableTwo to mapVariableOne.

Syntax:

mapVariableOne.putAll(Map mapVariableTwo);

Parameters:

ParamData typeDescription
anotherMapMapThe map object to be added

Returns: Void

Example:

mapVariableOne = {};mapVariableOne.a = 1;
mapVariableTwo = {};mapVariableTwo.b = 2;mapVariableTwo.c = 3;
mapVariableOne.putAll(mapVariableTwo);
log mapVariableOne; // { a: 1, b: 2, c: 3 }

remove#

The remove() function takes key as arguments, and removes the specified key along with its value from mapVariable.

Syntax:

mapVariable.remove(String key);

Parameters:

ParamData typeDescription
keyStringThe key which will be removed along with the value.

Returns: Void

Example:

mapVariable = {};mapVariable.a = 1;mapVariable.b = 2;mapVariable.c = 3;
mapVariable.remove("a");
log mapVariable; // { b: 2, c: 3 }

removeAll#

The removeAll() function takes list of keys as arguments, and removes the specified keys along with its values from mapVariable.

Syntax:

mapVariable.removeAll(List keys);

Parameters:

ParamData typeDescription
keysListThe list of keys which will be removed along with the values.

Returns: Void

Example:

mapVariable = {};mapVariable.a = 1;mapVariable.b = 2;mapVariable.c = 3;
removeKeys = ["b", "c"];mapVariable.removeAll(removeKeys);
log mapVariable; // { a: 1 }

get#

The get() function takes mapVariable and searchKey as arguments. It returns the value mapped to the searchKey in mapVariable.

Note :If the key is not found, the function will return null

Syntax:

mapVariable.get(String searchKey);

Parameters:

ParamData typeDescription
searchKeyStringThe key whose corresponding value will be returned.

Returns: The return type will depend on the data type of the returned value.

Example:

mapVariable = {};mapVariable.a = 1;mapVariable.b = 2;mapVariable.c = 3;
value = mapVariable.get("a");log value; // 1

size#

The size() function takes a mapVariable as argument, and returns the count of key-value pairs in the map.

Syntax:

mapVariable.size();

Returns: Number

Example:

mapVariable = {};mapVariable.a = 1;mapVariable.b = 2;mapVariable.c = 3;
size = mapVariable.size();log size; // 3

parse#

The parse() function takes a JSON formatted text as an argument, and returns a key-value pair map object.

Syntax:

new NameSpace("map").parse(String jsonString)

Returns: Map

Example:

jsonString = "{\"employee\":{\"name\":\"User\",\"id\":1,\"role\":\"Manager\",\"department\":\"Engineering\"}}"; // escaped json string
parsedMap = new NameSpace("map").parse(jsonString);log parsedMap; // {"employee":{"name":"User","id":1,"role":"Manager","department":"Engineering"}}

toString#

The toString() function takes a mapVariable as argument, and returns the JSON formatted text.

Syntax:

mapVariable.toString();

Returns: String

Example:

mapVariable = {};mapVariable.a = 1;mapVariable.b = 2;mapVariable.c = 3;
json = mapVariable.toString();log json; // 3

keys#

The keys() function takes a mapVariable as argument, and returns the keys of the given map.

Syntax:

mapVariable.keys();

Returns: list

Example:

mapVariable = {};mapVariable.a = 1;mapVariable.b = 2;mapVariable.c = 3;json = mapVariable.keys();log json; // [a,b,c]

clear#

The clear() function removes all the specified keys along with its values from mapVariable.

Syntax:

mapVariable.clear();

Returns: Void

Example:

mapVariable = {};mapVariable.a = 1;mapVariable.b = 2;mapVariable.c = 3;mapVariable.clear();log mapVariable; // {}