Array_findLastObject |
Homepage Containers |
Searches for the last occurrence, starting with startIndex, of the specified object, and returns the index for this element.
foundAt := Array_findLastObject(ArrayObject, searchObject, startIndex = 0)
| ArrayObject | The Array object to use for the current operation. |
| searchObject | The class object to search for. |
| startIndex | The index to start searching from. If omitted, the search starts with the last item. |
The index for the last matching element, starting with startIndex.
If there is no such element, the function returns 0.
The function's return can be used as a quasi-boolean value; the statement if Array_findLastObject(...) would be true if an element is found, and false otherwise.
If ArrayObject is NULL (0 or blank), the empty string is returned, to indicate an error.
Index values start at 1 and "wrap".
Array_indexOf, Array_lastIndexOf, Array_regexIndexOf
Array_findMatch, Array_findLastMatch
Array_findObject, Array_lastUnset
;Creates a new Array (of length 10). myArray := Array_new(10) ;Creates some String objects aString1 := String_new("Value1") aString2 := String_new("Value2") aString3 := String_new("Value1") ;Adds the Strings to myArray Array_set(myArray, 1, aString1) Array_set(myArray, 2, aString2) Array_set(myArray, 3, aString3) ;Searches for <aString3>. searchObject := aString3 if foundAt := Array_findLastObject(myArray, searchObject, 2) { ;foundAt contains the index for the element. MsgBox, % """" . searchObject . """ is found at index " foundAt "." } else { ;foundAt = 0 (i.e. not found) MsgBox, % "Search value was not found." }