Sort list by item length

Sort a list by item character count - shortest first by default, longest first with Order flipped. Ties are broken alphabetically so output is stable. Same op as Sort a list with Mode pre-set to By length.

Input
Ready
Output
Live

Character-count sort with alphabetical tiebreak

Each line's `.length` drives the sort - `"kiwi"` (4 chars) before `"apple"` (5) before `"grapes"` (6) before `"banana"` (6, tied with grapes but sorts later alphabetically). Stable output: same input always yields the same sorted list.

Order defaults to ascending (shortest first). Flip to descending for longest first. Case sensitive only matters on the alphabetical tiebreak for items of identical length: off (default) treats `Apple` and `apple` as equal under base-sensitivity `localeCompare`, so the stable sort keeps them in their input order; on distinguishes them so they sort as separate tied items. It has no effect on the length comparison itself - two items of different length sort the same either way.

For finding just the shortest or longest N items, chain Head (keeps first N) after this sort. For the raw extremes metric, use Find longest and shortest.

How to use sort list by item length

  1. 1Paste your list into the input panel
  2. 2Default Mode is By length (Order ascending)
  3. 3Flip Order to descending for longest-first
  4. 4For just the N shortest / longest items, chain Head
  5. 5Case sensitive only affects the alphabetical tiebreak on equal-length items (off = `Apple`/`apple` equal, stable; on = distinguishable)

Keyboard shortcuts

Drive ListShift without touching the mouse.

Shortcut Action
Ctrl ZUndo last input change
Ctrl Shift ZRedo
Ctrl Shift EnterToggle fullscreen focus on the editor
EscExit fullscreen
Ctrl KOpen the command palette to jump to any tool
Ctrl SSave current pipeline draft Plus
Ctrl PRun a saved pipeline Plus

What this tool actually does

Pre-configured By-length variant of Sort a list.

Character-count sort

Compares `line.length` - the raw character count. Unicode surrogate pairs (emoji) count as 2 in JavaScript, which can surprise you if your input has astral-plane characters.

Alphabetical tiebreak

Two items of the same length fall back to `localeCompare` ordering. Keeps output predictable and stable across runs.

Ascending default

Shortest first. Flip Order for longest first - useful when hunting for outlier-long rows in a log dump.

Works on any text

Paste words, lines of code, URLs, sentences - the op is content-agnostic. Measures whatever text is on each line.

Stable sort since ES2019

Identical length + identical alpha tiebreak → original relative order preserved. Safe to re-run without churn.

Worked example

Default: Mode By length, Order ascending. `kiwi` (4) first; `banana` and `grapes` tied at 6 - alpha tiebreak puts `banana` first.

Input
apple
banana
kiwi
grapes
Output
kiwi
apple
banana
grapes

Settings reference

Explore how each option affects the output using the sample input.

Setting What it does Effect on the sample
Order: Ascending (default) Sorts items from shortest to longest; alphabetical tiebreak on equal-length items kiwi apple banana grapes
Order: Descending Sorts items from longest to shortest; alphabetical tiebreak still applies on equal-length items banana grapes apple kiwi
Case sensitive: On Only affects the alphabetical tiebreak when two items have the same length; distinguishes `Apple` from `apple` as separate tied items. Does not affect the length comparison itself. No visible change on this sample - all items are lowercase and no two same-length items differ only in case. On an input like `[Apple, apple, PEARS, pears]` the toggle would matter.

FAQ

Does the Case sensitive toggle affect sorting on this page?
Only on the alphabetical tiebreak. Length mode compares `line.length` first - case has no meaning there, and items of different length sort identically regardless of the toggle. When two items have the same length, the tiebreak uses `localeCompare` with the toggle's sensitivity: off (default) treats `Apple` / `apple` as equal under base sensitivity so the stable sort keeps them in input order; on treats them as distinct tied items.
Can I sort items in descending order?
Yes, select 'Descending' in the 'Order' option to sort from longest to shortest.
Does the tool handle empty items?
Yes, empty items are considered and will appear first when sorting in ascending order.
Can I download the sorted list?
Yes, you can copy the result or hit 'Download' to save it as a plain text file.