Choose where you’d like to start

getKey

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,

ParameterData typeDescription
<variable>AS APPLICABLEVariable 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 APPLICABLEThe 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

Get Started Now

Execute