Skip to main content

array.find(item)

Finds a value within an array

Availability

Device + Agent

Parameters

Name Type Description
item Any Any Squirrel data type

Returns

Integer

Description

This method looks for the value — which may be of any Squirrel data type — passed as its parameter by comparing it to each of the target array’s items, one by one. If it finds the value, it returns the matching item’s index as an integer. If no matching item is found, the method returns null.

Even if multiple sought-for items exist within the target array, find() will only return the index of the first one. If you need to locate multiple matching items, iterate through the array’s items and compare each one individually:

foreach (index, item in array)  {
    if (item == match_value)  {
        server.log(format("There is a match at index %u", index));
    }
}

Array items which are not numerical or string values — ie. arrays, blobs, functions, objects and tables — will be compared by reference, not value.

Example Code