ArrayFind
Takes an array of objects and returns the first element that matches a given condition. Unlike ArrayFilter, which returns all matching elements, ArrayFind stops at the first match and returns it as a single object, not an array.
Reference
Parameters
array
The array of items to search.
Component data2-core-types@Getter
filter
The condition used to identify the first matching item.
Component data2-core-functions@Function
Example
Input
[
{ "name": "Alice", "car_color": "yellow" },
{ "name": "Bob", "car_color": "blue" },
{ "name": "Carol", "car_color": "yellow" }
]
Condition: car_color == "yellow"
Output:
{ "name": "Alice", "car_color": "yellow" }
Note: Even if multiple elements match the condition, only the first occurrence is returned. If no elements match, the output will be empty. If you need all matching elements, consider using ArrayFilter instead.