findFirst function (builtin)
Syntax
float findFirst(array, value)
float findFirst(array, value, epsilon)
Parameters
- array (float[], string[], bool[])
Array for which an index of a value is requested.
For float arrays an epsilon must be specified. - value (float, string, bool)
Value to look for. - epsilon (float)
(only applicable for float arrays)
A tolerance in which float values are considered to be equal. Can be specified in order to deal with floating point imprecision.
Returns
Zero-based index of the first occurrence of value in array. If value is not found, -1 is returned.
Related
- Array types operators
- findFirst function (utility library)
- array initialization function
- sortIndices function
- sortRowIndices function
Examples
Basic example
const array1d = [1,2,3,4] const array2d = [1,2,3;4,5,6] Example --> print( findFirst(array1d, 2, 0) ) // 1 print(array1d[ findFirst(array1d, 2, 0) ]) // 2 print( findFirst(array2d, 4, 0) ) // 3 print(array2d[ findFirst(array2d, 4, 0) ]) // 4
Use float epsilon
const indices = comp(e) { all : scope.sx } Example --> print(indices) // (4)[6,8.1,6,8.1] print(findFirst(indices, 8, 0.5)) // 1
Copyright ©2008-2024 Esri R&D Center Zurich. All rights reserved.