[jq] Find the first or last position of a value

Created on November 30, 2026

Use index to find the first zero-based position of a value in an array. The filter returns null if there is no match.

printf '%s\n' '[10,20,30,20]' '[20,10]' '[10,30]' | jq 'index(20)'
1
0
null

Find the last match

Use rindex to find the last occurrence. The original array has 20 at positions 1 and 3.

printf '%s\n' '[10,20,30,20]' | jq 'rindex(20)'
3

rindex also returns null if there is no match.

Reference

jq