ArrayFind Function

Action

Finds the position of an element in an array.

Syntax

iPos = ArrayFind (aArray, aElem [, iMaxIndex])
Variable Description
iPos The returned position. INTEGER.
aArray The array to search. ARRAY OF ANYTYPE.
aElem The element to find. ANYTYPE.
iMaxIndex Optional: The number of elements to search. INTEGER.

Notes

ArrayFind searches the array for the element aElem, and returns the index value of the element. If you specify iMaxIndex, ArrayFind searches only the first iMaxIndex elements; otherwise, the entire array is searched.

If aArray is a multi-dimensional array, you need to specify which sub-array to search. ArrayFind treats each dimension of a multi-dimensional array as an array within an array.

If it does not find aElem, ArrayFind returns zero (0).

Example

[ ] INTEGER aiTempPerDay[5][4]
[ ] 
[-] testcase arrayfind_example ()
	[ ] 
	[-] aiTempPerDay = {...}
		[ ] {10, 12, 8, 17} 
		[ ] {-1, 0, 17, -9}
		[ ] {14, 1, 1, 0} 
		[ ] {75, 32, 18, 103}
		[ ] {9, -7, -2, 3}
	[ ] Print (ArrayFind (aiTempPerDay[1], 8)) // Prints 3 
	[ ] Print (ArrayFind (aiTempPerDay[5], -7)) // 2 
	[ ] Print (ArrayFind (aiTempPerDay[4], 103, 3)) // 0
	[ ] Print (ArrayFind (aiTempPerDay[2], 20)) // 0
	[ ] Print (ArrayFind (aiTempPerDay, {-1, 0, 17, -9})) // 2