get
Table of Contents
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>);
Parameter | Data type | Description |
<variable> | ANY DATA TYPE | Variable which will contain the returned element or key. |
<collection> | COLLECTION | The 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 TYPE | The 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