GitHubContribute in GitHub: Edit online

array_index_of()

Searches the array for the specified item, and returns its position.

Syntax

array_index_of(array,lookup)

Arguments

  • array: Input array to search.
  • lookup: Value to lookup. The value should be of type long, integer, double, datetime, timespan, decimal, string, or guid.
  • start_index: Search start position. A negative value will offset the starting search value from the end of the array by this many steps: abs(start_index). Optional.
  • length: Number of values to examine. A value of -1 means unlimited length. Optional.
  • occurrence: The number of the occurrence. Default 1. Optional.

Returns

Zero-based index position of lookup. Returns -1 if the value isn't found in the array.

For irrelevant inputs (occurrence < 0 or length < -1) - returns null.

Example

print arr=dynamic(["this", "is", "an", "example"]) 
| project Result=array_index_of(arr,"an")



Result
2

See also

If you only want to check whether a value exists in an array, but you are not interested in its position, you can use set_has_element(arr, value). This function will improve the readability of your query. Both functions have the same performance.