Skip to content

Latest commit

 

History

History
22 lines (17 loc) · 636 Bytes

get-the-last-item-from-an-array.md

File metadata and controls

22 lines (17 loc) · 636 Bytes

Get The Last Item From An Array

There are two ways to get the last item from an array using jq.

The one that is perhaps a bit more intuitive is to pipe the array to the last function.

$ echo '[1,2,3]' | jq '. | last'
3

Another approach is to use an array index expression to positionally grab the last element of the array. As is the case with some languages and libraries, -1 positionally refers to the last item in the array.

$ echo '[1,2,3]' | jq '.[-1]'
3