Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
搜索指定项的数组,并返回其位置。
语法
array_index_of(
数组,值 [, [, [,occurrence ]]])
详细了解语法约定。
参数
| 客户 | 类型 | 必需 | 说明 |
|---|---|---|---|
| array | dynamic |
✔️ | 要搜索的数组。 |
| 价值 | long、int、datetime、timespan、string、guid 或 bool | ✔️ | 要查找的值。 |
| 开始 | int |
搜索开始位置。 在 abs(start 步骤下,负值将从数组的末尾偏移起始搜索值)。 |
|
| 长度 | int |
要检查的值数。 值为 -1 表示长度没有限制。 | |
| 事件 | int |
出现的次数。 默认值为 1。 |
返回
返回查找的从零开始的索引位置。 如果在数组中找不到该值,则返回 -1。 对于不相关的输入(occurrence 0 或 length -1),返回 null。
例子
以下示例显示数组中特定单词的位置编号。
let arr=dynamic(["this", "is", "an", "example", "an", "example"]);
print
idx1 = array_index_of(arr,"an") // lookup found in input string
, idx2 = array_index_of(arr,"example",1,3) // lookup found in researched range
, idx3 = array_index_of(arr,"example",1,2) // search starts from index 1, but stops after 2 values, so lookup can't be found
, idx4 = array_index_of(arr,"is",2,4) // search starts after occurrence of lookup
, idx5 = array_index_of(arr,"example",2,-1) // lookup found
, idx6 = array_index_of(arr, "an", 1, -1, 2) // second occurrence found in input range
, idx7 = array_index_of(arr, "an", 1, -1, 3) // no third occurrence in input array
, idx8 = array_index_of(arr, "an", -3) // negative start index will look at last 3 elements
, idx9 = array_index_of(arr, "is", -4) // negative start index will look at last 3 elements
输出
| idx1 | idx2 | idx3 | idx4 | idx5 | idx6 | idx7 | idx8 | idx9 |
|---|---|---|---|---|---|---|---|---|
| 2 | 3 | -1 | -1 | 3 | 4 | -1 | 4 | -1 |
相关内容
使用 set_has_element(arr, value) 检查数组中是否存在值。 此函数将提高查询的可读性。 这两个函数具有相同的性能。