Skip to content

indexOf

indexOf(array, value) → number · Array

Find the 0-based position of the FIRST occurrence of a value in an array. Returns -1 if not found.

  • array (required): array to search in

  • value (required): value to find

bash
echo '{"items": ["Apple", "Banana", "Cherry"]}' \
  | utlx -e 'indexOf($input.items, "Banana")'
# 1 (0-based: Apple=0, Banana=1, Cherry=2)
utlx
{
  pos: indexOf($input.items, "Banana"),   // 1 (0-based index)
  missing: indexOf($input.items, "Grape") // -1 (not found)
}

Released under AGPL-3.0.