Keep N from the end, by position or by shape
Last mode (default) slices the final N items preserving order - `Array.slice(Math.max(0, length - n))`. If the list has fewer than N items, every item is kept. Random picks N items via a Fisher-Yates shuffle of a copy of the list, then slices the first N - unbiased, not positional.
Longest / Shortest sort the list by character count (descending / ascending) and take the first N. Character count is `String.length` on each trimmed-on-input line - multi-byte characters count as their UTF-16 code-unit length (emoji and supplementary-plane characters count as 2).
Sorting is stable (ES2019+), so ties preserve original input order. `N` greater than the list length is clamped to the list length. Pair with Head of a list for the other end - same three non-positional modes, opposite positional default.
How to use tail of a list
- 1Paste your list into the input panel
- 2Set `Keep N` to the number of items you want (default `5`)
- 3Pick mode: Last (default positional), Random, Longest, or Shortest
- 4Output updates live; `N` past the list length keeps everything
- 5For the first-N side, use Head of a list
Keyboard shortcuts
Drive ListShift without touching the mouse.
What this tool actually does
Four ways to pick N items from a list.
Last mode (default): positional tail
`Array.slice(length - n)` gives the last N items in their original order. The common case when "tail" means "recent" in a log or chronological list.
Random mode: unbiased sample of N
Fisher-Yates shuffles a copy of the list, then takes the first N. Each item has equal probability of being selected; no item repeats. Re-run gives different results (no seed).
Longest mode: N items with most characters
Sorts by `String.length` descending and takes the top N. Ties preserve input order (stable sort). Useful for surfacing verbose lines, long URLs, or detailed entries.
Shortest mode: N items with fewest characters
Sort ascending by length, take top N. Useful for IDs vs descriptions, or for finding empty-looking entries.
N clamped to list length
If your list has 10 items and `Keep N: 50`, you get all 10 - no padding, no error. If the list is empty, the output is empty too.
Worked example
Defaults `Keep N: 5, Pick: Last` on a 6-item list → the final 5 items in order.
apple orange banana grape melon berry
orange banana grape melon berry
Settings reference
How each option shapes the output using the sample above.
| Setting | What it does | Effect on the sample |
|---|---|---|
| `Keep N: 5, Pick: Last` (defaults) | Last 5 items, original order | `orange, banana, grape, melon, berry` |
| `Keep N: 3, Pick: Last` | Last 3 items | `grape, melon, berry` |
| `Keep N: 3, Pick: Random` | Unbiased random sample of 3 items | Different 3 items each run (no seed) |
| `Keep N: 2, Pick: Longest` | 2 items with most characters | `orange`, `banana` (both 6 chars, ties preserve order) |
| `Keep N: 2, Pick: Shortest` | 2 items with fewest characters | `apple`, `grape` (both 5 chars) |