arrays.index_to_str
arrays.index_to_str(array, index)
Description
Returns the element at the given index from the array as a string. The index is an integer value that represents the position of an element in the array. By default, the first element of an array has an index of 0, and the last element has an index of n-1, where n is the size of the array. Negative indexing allows accessing array elements from the end of the array. For example, an index of -1 refers to the last element in the array and an index of -2 refers to the second to last element in the array.
Param data types
ARRAY_STRINGS|ARRAY_INTS|ARRAY_FLOATS
, INT
Return type
STRING
Code samples
Example 1
The following example fetches an element at index 1 from an array of strings.
arrays.index_to_str(["test1", "test2", "test3", "test4"], 1) // "test2"
Example 2
The following example fetches an element at index -1 (last element of the array) from an array of strings.
arrays.index_to_str(["test1", "test2", "test3", "test4"], 0-1) // "test4"
Example 3
The following example fetches an element for an index greater than the size of the array, which returns an empty string.
arrays.index_to_str(["test1", "test2", "test3", "test4"], 6) // ""
Example 4
The following example fetches an element from an empty array.
arrays.index_to_str([], 0) // ""
Example 5
The following example fetches an element at index 0 from an array of floats. The output is returned as a string.
arrays.index_to_str([1.200000, 3.300000, 2.400000], 0) // "1.2"
Example 6
The following example fetches an element at index 2 from an array of integers. The output is in the form of a string.
arrays.index_to_str([1, 3, 2], 2) // "2"