Nth Smallest Element

Find the nth smallest element in an array by sorting in ascending order.

Code

General
echo "$arr" | jq --argjson n "$n" 'sort | .[$n - 1]'

Parameters

Array of numbers (JSON)

Position (1-indexed)

Server

More Bash Snippets