Skip to content

support pick(last) #2716

@pkoppstein

Description

@pkoppstein

Using a version of jq with pick/1:

$ jq -nc '[[10,20],30] | pick(first) '
[[10,20]]

./jq -nc '[[10,20],30] | pick(.[length-1])'
[null,30]

$ jq -nc '[[10,20],30] | pick(last) '
jq: error (at <unknown>): Out of bounds negative array index

$ jq -nc '[[10,20],30] | pick(.[-1]) '
jq: error (at <unknown>): Out of bounds negative array index

So the failure of pick(last) could be resolved by redefining def last: .[length-1];
but is there a better solution? It's not clear to me why pick(.[-1]) should fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions