Skip to main content

$find

The $find operator finds the first element in an array that matches a provided condition.

Input

  • An array containing an array to search and a condition to evaluate for each element

Output

  • The first element that satisfies the condition, or null if no element matches

Examples

Find Even Number

{
  "$find": [
    [1, 2, 3, 4, 5, 6],
    {
      "$eq": [
        {
          "$mod": [
            {
              "$var": ["current"]
            },
            2
          ]
        },
        0
      ]
    }
  ]
}
Result: 2

Find Object by Property

{
  "$find": [
    [
      {"name": "Alice", "age": 25},
      {"name": "Bob", "age": 30},
      {"name": "Charlie", "age": 35}
    ],
    {
      "$eq": [
        {
          "$var": ["current"]
        },
        {
          "$input": "name"
        },
        "Bob"
      ]
    }
  ]
}
Result: {"name": "Bob", "age": 30}