Skip to main content

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​

  1. Paste numbers β€” One per line, comma-separated, or space-separated. Tool detects.
  2. Pick direction β€” Ascending (default) or descending.
  3. Configure β€” Drop duplicates (or keep), drop NaN / non-numeric, configure precision.
  4. 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.

Open the tool β†—


Last updated: 2026-05-06 Β· Author: Ahsan Mahmood Β· Edit this page on GitHub