Array.find(filter) Last updated: 24. Jan 2023

Returns first item that mathces the specified filter function.

Parameters

Name Type Description
filter function Create a filter function to return the first item that matches the filter.

Returns

The first array item matching the specified filter.

Example

Data

{
"items" : [{ "id" : 1, "name" : "item one"}, {"id" : 2, "name" : "item two"}]
}

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
#{
    let item = items.find(x => x.id == 2);
    write(item.name);
}#

Output

The #JS code above produces the output shown below:
item two