What This Tool Does
This tool sorts lines of text using one of several methods: alphabetical (A–Z or Z–A), numeric (for lists of numbers), by line length, or reverse the original order. Options include case-sensitive sorting, removing duplicates, and locale-aware comparison for accented characters.
Inputs Explained
- Source Text: Paste any multi-line text — one item per line.
- Sort Method: Alphabetical A-Z, Z-A, numeric ascending/descending, by length, or reverse order.
- Case Sensitive: When checked, uppercase letters sort before lowercase.
- Remove Duplicates: Optional deduplication after sorting.
How It Works
The text is split by newlines into an array. The chosen sort method is applied using JavaScript's Array.sort with a custom comparator. Alphabetical uses localeCompare for proper handling of accents and Unicode. Numeric sort parses each line as a number. Length sort compares string lengths.
Formula / Logic Used
Sort Lines Alphabetically
Sort any list of lines alphabetically, numerically, by length, or reverse order.
Step-by-Step Example
Input:
banana Apple cherry 10 2 apple
Method: Alphabetical A-Z (case insensitive)
Output:
10 2 Apple apple banana cherry
For numeric sort: 2, 10, Apple, apple, banana, cherry (numbers first in ascending order, text alphabetically after).
Use Cases
- Alphabetize lists: Sort names, products, or tags into alphabetical order for reports and directories.
- Prioritize by length: Find the longest or shortest entries in a list — useful for URL slugs, titles, or tweet drafts.
- Numeric sorting: Sort numeric IDs, quantities, or prices when they're mixed into a text list.
- Reverse order: Flip the order of items quickly — e.g., reverse a timeline or playlist.
- Random shuffle: Shuffle lines to randomize quiz questions, playlists, or team rosters.
Assumptions and Limitations
- Numeric sort treats non-numeric lines as 0 (they cluster at the top/bottom of numeric sort).
- localeCompare uses your browser's default locale — sorting may differ slightly across locales for accented characters.
- Shuffle uses Math.random, which is pseudo-random, not cryptographic. For fair raffles, use a verifiable RNG.
- Stable sort is guaranteed in modern browsers, so equal keys preserve their relative input order.
Frequently Asked Questions
How does the alphabetical sort handle uppercase vs lowercase?
By default, the sort is case-insensitive — 'Apple' and 'apple' are grouped together. Enable 'Case sensitive sort' to put uppercase letters before lowercase in the output.
Why are my numbers sorting as '1, 10, 2, 20'?
That's alphabetical order. Use 'Numeric' sort to get the correct 1, 2, 10, 20 order. Alphabetical sort compares character by character — '1' comes before '2' but '10' comes between '1' and '2' because it starts with '1'.
What happens to empty lines?
By default, empty lines are removed before sorting. Uncheck 'Remove empty lines' to keep them — they'll sort to the top of alphabetical order since empty strings sort first.
Is the sort stable?
Yes. Modern JavaScript engines guarantee stable sort — when two lines compare equal, their relative input order is preserved. This matters when sorting by one key but wanting to retain another implicit order.
How does Unicode sorting work?
Case-insensitive sort uses localeCompare, which is Unicode-aware and handles accented characters (é sorts near e). Case-sensitive sort uses raw codepoint comparison, which may order accented characters differently.
Can I sort by something other than the whole line?
This tool sorts whole lines. For column-based sorting (like sorting CSV by a specific column), use a spreadsheet tool like Excel or Google Sheets.
How random is the shuffle?
It uses the Fisher-Yates shuffle with Math.random, which is unbiased and suitable for most casual use. For cryptographically random shuffles (e.g., lottery), use a tool built on crypto.getRandomValues.
Is my data saved?
No. All sorting runs entirely in your browser. Text never leaves your device and is not logged anywhere.
Sources and References
- MDN — Array.prototype.sort — JavaScript array sorting reference.
- MDN — String.prototype.localeCompare — Locale-aware string comparison.
- Wikipedia — Fisher-Yates Shuffle — The algorithm used for unbiased random shuffling.
- ECMAScript Specification — Sort — The official spec guaranteeing stable sort in modern engines.