By default, the sort method sorts elements alphabetically. To sort numerically just add a new method which handles numeric sorts (sortNumber, shown below) -

var numArray = [140000, 104, 99];
numArray.sort(function(a, b) {
  return a - b;
});

console.log(numArray);

Documentation:

Mozilla Array.prototype.sort() recommends this compare function for arrays that don't contain Infinity or NaN. (Because Infinity - Infinity is NaN, not 0).

Also examples of sorting objects by key.

Answer from aks on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › sort
Array.prototype.sort() - JavaScript - MDN Web Docs
The sort() method of Array instances sorts the elements of an array in place and returns the reference to the same array, now sorted. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code unit values.
🌐
W3Schools
w3schools.com › jsref › jsref_sort.asp
JavaScript Array sort() Method
The sort() method sorts the elements of an array. The sort() method sorts the elements as strings in alphabetical and ascending order. The sort() method overwrites the original array.
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-array-sort-numbers
Using JavaScript's sort Method for Sorting Arrays of Numbers | DigitalOcean
It can be tricky at first to understand the rules for the array sort method in JavaScript. This post should help with that!
🌐
freeCodeCamp
freecodecamp.org › news › how-to-sort-javascript-array-accurately
JavaScript Sort Array - How to Sort an Array Accurately
November 7, 2024 - For sorting an array of numbers, the comparison function should subtract the second number from the first number.
🌐
W3Schools
w3schools.com › js › js_array_sort.asp
JavaScript Array Sort
Using a sort function, like explained above, you can sort an numeric array in random order · const points = [40, 100, 1, 5, 25, 10]; points.sort(function(){return 0.5 - Math.random()}); ... The points.sort() method in the example above is not ...
🌐
Raddevon
raddevon.com › articles › sort-array-numbers-javascript
How do I sort an array of numbers in Javascript? » Rad Devon
In order to sort numbers, you’ll need to write a function that returns a negative number if a is less than b, returns a positive number if b is less than a, and returns 0 if the numbers are the same.
🌐
DEV Community
dev.to › elmarshall › sorting-an-array-of-number-strings-in-javascript-la7
Sorting an Array of Number Strings in JavaScript - DEV Community
May 4, 2020 - I didn't realize this is a case of another built in method for JavaScript. The function is actually an optional parameter, called the compareFunction, that allows you to define an alternative sort order. ... When the sort() method compares two values, it sends the values to the compare function, and sorts the values according to the returned (negative, zero, positive) value. The magic is that by performing an operation (subtraction) on the numbers in question, JavaScript converts them to integers.
Find elsewhere
🌐
Medium
medium.com › @us.panliu › how-to-use-the-javascript-array-sort-method-to-sort-arrays-of-numbers-strings-and-objects-94572b17663
How to use the JavaScript Array sort() method to sort arrays of numbers, strings, and objects. | by Pan Liu | Medium
December 16, 2021 - If compare(a,b) returns zero, the sort() method considers a equals b and leaves their positions unchanged. In this case, initially the a value is 8 and the b value is 2, and the comparator function is going to do a three-way comparison, it will check whether the a value is less than, greater than or equal to the b value. const numbers = [8, 2, 100, 4];const sortedNumbers = numbers.sort((a, b) =>{ if (a < b) { return -1; } else if (a > b) { return 1; } else { return 0; } })console.log(sortedNumbers);
🌐
Mimo
mimo.org › glossary › javascript › sort
JavaScript Sort Method: Advanced Array Sorting Techniques
Sorting arrays in JavaScript is simple and versatile with the sort() method. This method allows you to sort arrays of numbers, strings, or objects with custom functions.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-sort-numeric-array-using-javascript
JavaScript - Sort a Numeric Array - GeeksforGeeks
The sort() method in JavaScript, when used with a comparison function, can sort the numeric arrays in ascending or descending order. This is the most frequently used approach. ... const a = [5, 2, 9, 1, 7]; // Ascending order a.sort((x, y) => ...
Published: August 5, 2025
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-array-sort-numbers
array.sort() Does Not Simply Sort Numbers in JavaScript
January 26, 2021 - (a, b) => a - b is a short comparator to sort numbers. I recommend this form to sort the array of numbers in JavaScript.
🌐
Medium
medium.com › @jmin499 › javascript-sort-method-571d8bef61a1
JavaScript Sort Method. How to sort numbers inside an array… | by James Min | Medium
December 8, 2019 - JavaScript Sort Method How to sort numbers inside an array that’s unsorted? const numbers= [4, 1, 3, 2]; Easy! We can sort the numbers of array by using the sort() method. const numbers = [4, 1, 3 …
🌐
Medium
noncodersuccess.medium.com › sorting-arrays-like-a-pro-advanced-techniques-in-javascript-e3590b75d591
Sorting Arrays Like a Pro: Advanced Techniques in JavaScript | by NonCoderSuccess | Medium
April 14, 2024 - Even if objects have properties of different data types, the sort() method can be used to sort the array. The solution is to write a compare function to compare the property values: Sorting arrays in JavaScript might seem like a small thing, ...
🌐
Mokkapps
mokkapps.de › tips › js › how-to-sort-an-array-of-integers
JavaScript Tip: How to Sort an Array of Integers | Michael Hoffmann
January 2, 2023 - To sort an array of integers, we must provide a compare function that defines the sort order: ... const numbers = [10, 3, 45, 999, 20] const ascendingSortedNumbers = [...numbers].sort((a, b) => a - b) console.log(ascendingSortedNumbers) // [ ...
🌐
freeCodeCamp
freecodecamp.org › news › javascript-array-sort-tutorial-how-to-use-js-sort-methods-with-code-examples
JavaScript Array Sort – How to Use JS Sort Methods (With Code Examples)
May 24, 2020 - In this post, you will learn how to sort an array in JavaScript by using the sort( ) method for strings and numbers.
🌐
CodeSpeedy
codespeedy.com › home › how to sort array of numbers in javascript easily
How to sort array of numbers in JavaScript Easily - CodeSpeedy
October 8, 2018 - var tutorials = ["Java", "PHP", "JavaScript", "Python"]; tutorials.sort(); It will sort the elements just like the dictionary sorts its words. ... sort() method deals with string so if the numbers are taken as a string also it will give you ...
🌐
Envato Tuts+
code.tutsplus.com › home › javascript
Sorting Values With JavaScript | Envato Tuts+ - Code
February 24, 2023 - For this, we can make use of the following function: In the function, we use parseInt() to make sure the value is a number, and then we subtract both numbers to get a negative, positive, or zero value.