Truncate-or-pad to a fixed N
The op runs `items.slice(0, n)` to truncate, then appends the Pad with string until the length hits `n`. If your list has exactly `n` items, nothing changes. If more, the tail drops. If fewer, the tail grows with padding.
Pad with is literal text - default empty string produces blank padding lines. Set it to `-`, `N/A`, or a placeholder token to make the padded rows visually distinct. Every padded line is identical; this is not a serial-numbered filler.
Unlike Truncate (which only shortens) and Head (first-N selection), Set length always normalises to exactly N - padding up *or* trimming down as needed.
How to use set list length
- 1Paste your list into the input panel
- 2Set `Target length` to the exact number of items you want (default `10`)
- 3Set `Pad with` to the placeholder for short lists (default blank)
- 4Output always has exactly `N` items - truncated if long, padded if short
- 5For truncation-only behaviour, use Truncate a list
Keyboard shortcuts
Drive ListShift without touching the mouse.
What this tool actually does
Truncate-or-pad to a fixed count. Two options.
Exact length output
The output is always exactly `N` items. Longer lists lose their tail; shorter lists gain padded rows until they hit `N`.
Any string as padding
Default Pad with is empty (blank lines). Use `-`, `N/A`, `--empty--`, or any other token to visually mark padded rows. The same string is used for every padded line.
Order preserved
When truncating, items at the tail are dropped (not from the head or middle). When padding, new lines are appended after your existing items, not interspersed.
Blank input + Pad set = all-padding output
If you paste nothing and set `N = 5` with `Pad with = -`, the output is five `-` lines. Useful for generating fixed-count filler.
Zero-or-negative N collapses to an empty list
`parseInt` on invalid values gives NaN which coerces to 0 in the slice - output is empty. Set a positive integer to get a meaningful result.
Worked example
Default `N = 10`, Pad = blank. 12-item input truncates to the first 10 items; no padding needed.
Item 1 Item 2 Item 3 Item 4 Item 5 Item 6 Item 7 Item 8 Item 9 Item 10 Item 11 Item 12
Item 1 Item 2 Item 3 Item 4 Item 5 Item 6 Item 7 Item 8 Item 9 Item 10
Settings reference
How each option shapes the output using the sample above (12-item input).
| Setting | What it does | Effect on the sample |
|---|---|---|
| `N: 10`, Pad: blank (defaults) | Truncates to first 10 items (no padding needed here) | `Item 1`..`Item 10` |
| `N: 5`, Pad: blank | Truncates to first 5 items | `Item 1`..`Item 5` |
| `N: 15`, Pad: `-` | 12 items + 3 padded rows of `-` | `Item 1`..`Item 12`, then `-`, `-`, `-` |
| `N: 15`, Pad: blank | 12 items + 3 blank padded rows | `Item 1`..`Item 12`, then three blank lines |
| `N: 0` (or negative / non-numeric) | Empty output | (empty) |