Choose where you’d like to start

get

Overview

The get function retrieves values from a collection using either an index or a key.

Note: Index starts from 0.

Return Type

  • ANY DATA TYPE

Syntax

<variable> = <collection>.get(<indexValue>);

​(OR)

<variable> = <collection>.get(<key>);
ParameterData typeDescription
<variable>ANY DATA TYPEVariable which will contain the returned element or key.
<collection>COLLECTIONThe collection from which the specified value or element needs to be retrieved.
<indexValue>NUMBER

The index of the element which will be returned.

Note: The range of the index is from 0 through the collection size - 1. Indices outside this range will yield a null.

<key>ANY DATA TYPEThe key for which the value will be returned.

Examples

 names  =  Collection("name10","name2","name6","name1");
 first_name  =  names.get(0); // the value "name10" is assigned to first_name
 fifth_name  =  names.get(4); // Throws a run-time error - "Given index 4 is greater than the list size"

 names =  Collection("name1":"John","name2":"Bill");
 name  =  names.get("name1"); // the value "John" is assigned to name
 name  =  names.get("name3"); // returns null

Related links

Get Started Now

Execute