getLastKey
Table of Contents
Overview
The getLastKey function returns the key of a specified value's last occurrence, or the index of a specified element's last occurrence, 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's last occurrence:
<variable> = <collectionVariable>.getLastKey(<value>);
(OR)
To get the index value of an element's last occurrence:
<variable> = <collectionVariable>.getLastKey(<element>);
where,
Parameter | Data type | Description |
<variable> | Variable which will hold the returned value. | AS APPLICABLE |
<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" : 5); info productVersion.getLastKey( 5 ); // Returns "Mail"
products = collection("Creator", "CRM", "Creator"); info products.getLastKey( "Creator" ); // Returns 2