update
Overview
The update function updates a specified value of a key or a specified element in a collection.
Syntax
To update the value of a key:
<collectionVariable>.update(<key>, <updateValue>);
(OR)
To update an element:
<collectionVariable>.update(<elementIndex>, <updatedValue>);
where,
Parameter | Data type | Description |
<collectionVariable> | COLLECTION | The variable in which the value of a key or an element will be updated. |
<key> | All Data Types | The key whose value will be updated. If a new key is specified, the key-value pair will get added as a new pair. |
<elementIndex> | NUMBER | The index of the element which will be updated with a new value. If the specified index does not exist, a runtime error will be encountered. |
<updatedValue> | ALL DATA TYPES | The value which will replace the existing value. |
Examples
products = collection("Creator", "CRM", "Campaigns"); products.update(2, "Analytics"); //replaces "Campaigns" with "Analytics" info products; // Returns, Creator,CRM,Analytics
productVersion = collection("Creator" : 5, "CRM" : 2); productVersion.update("CRM", 3); // replaces the value 2 with 3 info productVersion; // Returns, {"Creator":5,"CRM":3}