Skip to main content

$nth

The $nth operator returns the element at the specified index in an array.

Input

  • An array containing an array value and an integer index

Output

  • The element at the specified index in the array, or null if the index is out of bounds

Examples

Get Element at Index

{
  "$nth": [
    [1, 2, 3, 4, 5],
    2
  ]
}
Result: 3 (element at index 2, 0-indexed)

From Field

{
  "$nth": [
    {
      "$input": "items"
    },
    0
  ]
}
Result: The first element of the items field array, or null if the array is empty