배열에서 지정된 항목을 검색하고 해당 위치를 반환합니다.
구문
array_index_of(
배열, 값 [,start [,length [,occurrence ]]])
구문 규칙에 대해 자세히 알아봅니다.
매개 변수
| 이름 | 유형 | 필수 | 설명 |
|---|---|---|---|
| 배열 | dynamic |
✔️ | 검색할 배열입니다. |
| 값 | long, int, datetime, timespan, string, guid 또는 bool | ✔️ | 조회할 값입니다. |
| start | int |
검색 시작 위치입니다. 음수 값은 시작abs(배열의 끝에서 시작 검색 값을 오프셋합니다. |
|
| 길이 | int |
검사할 값의 수입니다. 값이 -1이면 길이가 무제한입니다. | |
| 발생 | int |
발생 횟수입니다. 기본값은 1입니다. |
반품
조회의 인덱스 위치(0부터 시작하는 인덱스)를 반환합니다. 배열에 값이 없으면 -1을 반환합니다. 관련이 없는 입력(발생 0 또는 < -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)를 사용하여 배열에 값이 있는지 확인합니다. 이 함수는 쿼리의 가독성을 향상시킵니다. 두 함수의 성능은 동일합니다.