array_index_of()
搜尋陣列中的指定專案,並傳回其位置。
Syntax
array_index_of(
陣 列,
value [start [length [,
,
,
occurrence ]]])
深入瞭解 語法慣例。
參數
名稱 | 類型 | 必要 | Description |
---|---|---|---|
array | dynamic |
✔️ | 要搜尋的陣列。 |
value | long、int、datetime、timespan、string、guid 或 bool | ✔️ | 要查閱的值。 |
開始 | int |
搜尋開始位置。 負值會依 abs( 開始) 步驟,從數組結尾位移開始搜尋值。 |
|
length (長度) | int |
要檢查的值數目。 -1 的值表示沒有長度限制。 | |
occurrence | int |
出現次數。 預設值是 1。 |
傳回
傳回以零起始的查閱索引位置。 如果在陣列中找不到值,則傳回 -1。 針對不相關的輸入傳回 null , (出現< 0 或 長度< -1) 。
範例
下列範例顯示陣列中特定字組的位置數目。
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
) 檢查陣列中是否有值。 此函式會改善查詢的可讀性。 這兩個函式具有相同的效能。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應