array_index_of()array_index_of()

搜索指定项的数组,并返回其位置。Searches the array for the specified item, and returns its position.

语法Syntax

array_index_of(array , value)array_index_of(array , value)

参数Arguments

  • array :输入要搜索的数组。array : Input array to search.
  • value :要搜索的值。value : Value to search for. 此值的类型应为长型、整数型、双精度型、日期/时间型、时间范围型、十进制型、字符串型或 guid。The value should be of type long, integer, double, datetime, timespan, decimal, string, or guid.

返回Returns

查找的从零开始的索引位置。Zero-based index position of lookup. 如果在数组中找不到该值,则返回 -1。Returns -1 if the value isn't found in the array.

示例Example

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

另请参阅See also

如果仅希望检查数组中是否存在某个值,但对其位置不感兴趣,可以使用 set_has_element(arr, value)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.