Keep N from the start, by position or by shape
First mode (default) takes the first N items preserving order - `Array.slice(0, 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 line - multi-byte characters count as their UTF-16 code-unit length.
Sorting is stable (ES2019+), so ties preserve original input order. `N` greater than the list length is clamped to the list length. Pair with Tail of a list for the other end - same three non-positional modes, opposite positional default.
How to use head of a list
- 1Paste your list into the input panel
- 2Set `Keep N` to the number of items you want (default `5`)
- 3Pick mode: First (default positional), Random, Longest, or Shortest
- 4Output updates live; `N` past the list length keeps everything
- 5For the last-N side, use Tail 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.
First mode (default): positional head
`Array.slice(0, n)` gives the first N items in their original order. The common case when "head" means "first few" 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; 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.
Shortest mode: N items with fewest characters
Sort ascending by length, take top N. Ties preserve input order.
N clamped to list length
If your list has 3 items and `Keep N: 10`, you get all 3 - no padding, no error. Empty input returns empty output.
Worked example
Defaults `Keep N: 5, Pick: First` on a 7-item list → first 5 items in order.
Apple Banana Cherry Date Elderberry Fig Grape
Apple Banana Cherry Date Elderberry
Settings reference
How each option shapes the output using the sample above.
| Setting | What it does | Effect on the sample |
|---|---|---|
| `Keep N: 5, Pick: First` (defaults) | First 5 items, original order | `Apple, Banana, Cherry, Date, Elderberry` |
| `Keep N: 3, Pick: First` | First 3 items | `Apple, Banana, Cherry` |
| `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 | `Elderberry` (10 chars), then next-longest (`Banana` / `Cherry` tied at 6 - first wins by input order → `Banana`) |
| `Keep N: 2, Pick: Shortest` | 2 items with fewest characters | `Fig` (3 chars), then `Apple` (5) |