findFirst function (Builtin)

Syntax

  • float findFirst(array, value)
  • float findFirst(array, value, epsilon)

Parameters

  1. array—(float[], bool[], string[])
    Array for which an index of a value is requested. For float arrays an epsilon must be specified.
  2. value—(float, bool, string)
    Value to look for.
  3. epsilonfloat
    (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

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