Map functions
put#
The put() function takes key and value as arguments, and adds the key-value pair to the mapVariable.
Syntax:
mapVariable.put(Stringkey,Objectvalue);
Parameters:
| Param | Data type | Description |
|---|---|---|
| key | string | The key to be added to the map. |
| Value | string | The 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(MapmapVariableTwo);
Parameters:
| Param | Data type | Description |
|---|---|---|
| anotherMap | Map | The 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(Stringkey);
Parameters:
| Param | Data type | Description |
|---|---|---|
| key | String | The 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(Listkeys);
Parameters:
| Param | Data type | Description |
|---|---|---|
| keys | List | The 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(StringsearchKey);
Parameters:
| Param | Data type | Description |
|---|---|---|
| searchKey | String | The 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; // 1size#
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; // 3parse#
The parse() function takes a JSON formatted text as an argument, and returns a key-value pair map object.
Syntax:
new NameSpace("map").parse(
StringjsonString)
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; // 3keys#
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; // {}