sort-numbers
Sorting numbers orders them ascending (smallest first) or descending (largest first). Sounds trivial, but the JavaScript default β arr.sort() β uses lexicographic order, so [1, 10, 2] sorts to [1, 10, 2] not [1, 2, 10]. The ZTools Sort Numbers tool sorts numerically (not lexicographically), handles decimals / negatives / scientific notation correctly, and supports up to a million values in a millisecond. Output as comma list, line list, or JSON array.
Use casesβ
Sort a column from a spreadsheetβ
Pasted a numeric column to verify its range. Sort ascending β first value is min, last is max, instantly visible.
Identify outliers visuallyβ
After sorting, the largest values cluster at one end. Anomalies stand out.
Prepare data for plottingβ
A line chart wants x-sorted points. Sort first, then plot.
Find the median in secondsβ
For a list of N numbers, median = sorted[N/2] (or average of two middle values for even N). Sort, count, done.
How it worksβ
- Paste numbers β One per line, comma-separated, or space-separated. Tool detects.
- Pick direction β Ascending (default) or descending.
- Configure β Drop duplicates (or keep), drop NaN / non-numeric, configure precision.
- Read sorted output β Same format as input. Stats panel shows count, min, max for verification.
Examplesβ
Input: [10, 1, 5, 3, 7]
Output: Ascending: [1, 3, 5, 7, 10]. Descending: [10, 7, 5, 3, 1].
Input: [1.5, 1.05, 1.5e3]
Output: Ascending: [1.05, 1.5, 1500] β scientific notation handled correctly.
Input: [β5, 10, 0, β1]
Output: Ascending: [β5, β1, 0, 10] β negatives ordered correctly.
Frequently asked questionsβ
Why does my JavaScript sort give wrong order?
arr.sort() is lexicographic. arr.sort((a, b) => a - b) is numeric. This tool always uses the numeric form.
Maximum size?
Million values sort in <1 second. Beyond that, browser starts struggling.
Stability?
JavaScript sort is stable since ES2019. Equal values keep their original order.
Drop duplicates?
Optional toggle β useful when the question is "what unique values exist".
Privacy?
Client-side.
Tipsβ
- For very large lists, paste as JSON β saves the parse-from-text step.
- When sort produces unexpected results, check for non-numeric entries (one stray "abc" in 10,000 numbers).
- For multi-column sort (CSV with primary and secondary key), use the Sort CSV Data tool β this one is single-list.
- After sorting, also note count and min/max β quick sanity check on the dataset.
Try it nowβ
The full sort-numbers runs in your browser at https://ztools.zaions.com/sort-numbers β no signup, no upload, no data leaves your device.
Last updated: 2026-05-06 Β· Author: Ahsan Mahmood Β· Edit this page on GitHub