Skip to content

findIndex

findIndex(array, predicate) → number · Array

Returns the zero-based index of the FIRST matching element, or -1 if not found.

  • array (required): the array to search

  • predicate (required): lambda (element) -> boolean

bash
echo '{"users": [{"id": 1}, {"id": 2}, {"id": 3}]}' \
  | utlx -e 'findIndex($input.users, (u) -> u.id == 2)'
# 1
utlx
{
  position: findIndex($input.users, (u) -> u.id == 2),
  missing: findIndex($input.users, (u) -> u.id == 99)
}

Also: findLastIndex(array, predicate) — searches from the end.

Released under AGPL-3.0.