Coding at Dawn
Published in

Coding at Dawn

How to sort an array numerically in JavaScript

The default ECMAScript sort is alphabetical, so a little magic is needed to sort an array in numerical order.

Photo by Sora Sagano on Unsplash

Ever try to sort an array of integers in JavaScript using .sort() and get a weird result, where the order was not numeric?

--

--

--

Laid-back programming + relaxing photography

Recommended from Medium

GraphQL ToDo List With Apollo, TypeScript and Node.js

10 Tricks to Optimize Your Angular App

Learn about Destructuring in JavaScript

Storybook on-demand architecture

LeetCode SQL| 197. Rising Temperature

JavaScript Promises

How I Share Components and Manage Shared libraries with Bit

Type Conversion and Coercion

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dr. Derek Austin 🥳

Dr. Derek Austin 🥳

Platform Architect (Next.js) ♦ Frontend Software Engineer ♦ SEO & Web Performance Expert ♦ Developer Advocate ♦ My Favorite Tech Stack: Next (React) + Tailwind

More from Medium

4 JavaScript Promise Methods — All, AllSettled, Any, and Race

How to Sort an Array without Using JavaScript’s Sort Method

Stacks: The Deeper Data Structures in JavaScript

React — Displaying Different Things As Screen Size Changes