Skip to main content

The "array_find_index" Function

Syntax#

array_find_index(id, val);
ArgumentTypeDescription
idarrayThe index of a previously-created array to search
valanyThe value to search for

Description#

Searches an array for a value and returns the index, if found, or -1 if the value does not exist in the array. If the input is not an array, but happens to match the search value regardless, 0 will be returned instead.

To search a multidimensional array, input any parent arrays before the child array to be searched, e.g. my_array[0][0].

Example#

var my_array = [ 1, 2, 3, [ "a", "b", "c", [ ".", "!", "?" ] ] ];
draw_text(25, 25, string(array_find_index(my_array[3], "b")));