getKey
Table of Contents
Overview
The getKey function returns the key of a specified value, or the index of a specified element, in a collection.
Return Type
- Data type of the return value will depend on the data type of the key.
- Returns null if the specified value is not found.
- Data type is NUMBER if the index of an element is returned. Returns -1 if the specified element is not found.
Syntax
To get the key of a specified value:
<variable>=<collectionVariable>.getKey(<value>);
(OR)
To get the index value of an element:
<variable>=<collectionVariable>.getKey(<element>);
where,
| Parameter | Data type | Description |
| <variable> | AS APPLICABLE | Variable which will hold the returned value. |
| <collectionVariable> | COLLECTION | The variable from which the key or the index will be returned. |
| <value> | AS APPLICABLE | The value whose key will be returned. This function returns null if the specified value is not found. |
| <element> | AS APPLICABLE | The element whose index value will be returned. This function returns -1 if the specified element is not found. |
Examples
productVersion=collection("Creator":5,"CRM":2,"Mail":8); product=productVersion.getKey(5); info product;// Returns "Creator"
products=Collection("Creator","CRM","Mail"); indexNum=products.getKey("CRM"); info indexNum;// Returns 1