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
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-sort-the-elements-of-an-array-in-ascending-order
JavaScript - Sort JS Array in Ascending Order - GeeksforGeeks
July 23, 2025 - Pass the comparator function in array.sort() to sort the array in ascending order. ... Please go through this, How to Sort Numeric Array using JavaScript?, to know how the javascript array sort function works.
🌐
W3Schools
w3schools.com › jsref › jsref_sort.asp
JavaScript Array sort() Method
// Create an Array const points = [40, 100, 1, 5, 25, 10]; // Sort the numbers in descending order: points.sort(function(a, b){return b-a}); let highest = points[0]; Try it Yourself » ... // Create an Array const points = [40, 100, 1, 5, 25, 10]; // Sort the numbers in ascending order: points.sort(function(a, b){return a-b}); let highest = points[points.length-1]; Try it Yourself »
Discussions

Sorting through arrays in ascending order
I’m not sure why I’m not getting these letters to ascend in order. I’m using the sort method with the arrow function. function alphabeticalOrder(arr) { // Only change code below this line return arr.sort((a,b) => a - b); // Only change code above this line } console.log(alphabeticalO... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
9
0
September 10, 2021
javascript - How can I sort an array of integers? - Stack Overflow
If anyone doesn't understand how Array.sort() works with integers, read this answer. ... By default, the sort() method sorts the values as strings in alphabetical and ascending order. More on stackoverflow.com
🌐 stackoverflow.com
how to sort an array of numbers in ascending order in linear time?
If you want to sort in linear time you have to make assumptions about the input More on reddit.com
🌐 r/algorithms
33
12
July 29, 2021
how does array.sort((a, b) => {return a - b};) order an array of integers in ascending order instead of returning the result of (a-b) and storing it into the array?
Here's a basic sort function: function bubbleSort (array, callback) { let length = array.length; while (length > 0) { for (let i = 0; i < length - 2; i++) { const current = i; const next = i + 1; if (callback(array[current], array[next]) > 0) { [array[current], array[next]] = [array[next], array[current]]; } } length--; } return array; } Similar to JS's sort function, it takes a callback function which receives two elements from the array and returns a number. If the returned number is larger than zero, the elements are swapped. So if we were to sort an array like this: ['A', 'N', 'C'] With a function like this: function (a, b) { if (a < b) { return -1; } else { return 1; } } It will compare each letter (the < and > operators can be used to compare strings: 'Aardvark' < 'Anteater' === true), and sort them in ascending order. ['A', 'C', 'N'] More on reddit.com
🌐 r/learnjavascript
5
4
April 24, 2021
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-program-to-sort-the-elements-of-an-array-in-ascending-order
JavaScript – Sort JS Array in Ascending Order | GeeksforGeeks
November 14, 2024 - Pass the comparator function in array.sort() to sort the array in ascending order. ... Please go through this, How to Sort Numeric Array using JavaScript?, to know how the javascript array sort function works.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-sort-javascript-array-accurately
JavaScript Sort Array - How to Sort an Array Accurately
November 7, 2024 - The sort() method can be used to sort elements of an array in ascending order based on Unicode character code values by default.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
Sorting through arrays in ascending order - Curriculum Help - The freeCodeCamp Forum
September 10, 2021 - I’m not sure why I’m not getting these letters to ascend in order. I’m using the sort method with the arrow function. function alphabeticalOrder(arr) { // Only change code below this line return arr.sort((a,b) => a - b); // Only change code above this line } console.log(alphabeticalOrder(["a", "d", "c", "a", "z", "g"])); Link below https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-metho...
Find elsewhere
🌐
Medium
medium.com › @amirakhaled2027 › javascripts-array-sort-method-3edbc7fbca22
JavaScript’s Array sort() Method
July 26, 2024 - The sort() method is an intrinsic method of the Array object in JavaScript. It sorts the elements of an array in place, modifying the original array, and returns the sorted array.
🌐
Programiz
programiz.com › javascript › library › array › sort
JavaScript Array sort() | Programiz
March 4, 2024 - In this tutorial, we will learn about the JavaScript Array sort() method with the help of examples. The sort() method sorts the items of an array in a specific order (ascending or descending).
🌐
LogRocket
blog.logrocket.com › home › javascript’s sort()method: from basics to custom sorting
JavaScript's sort()method: From basics to custom sorting - LogRocket Blog
March 7, 2025 - To recap the previous section, the JavaScript sort() array method takes an optional compare function as a callback. If you don’t pass a callback, the array’s elements will be coerced to strings and are sorted in ascending order of the numerical values of their UTF-16 code units.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.some()
JavaScript Array sort: Sorting an Array More Effectively
November 8, 2024 - It changes the positions of the elements in the original array and returns the sorted array. By default, the sort() method sorts the array elements in ascending order, placing the smallest value first and the largest value last.
🌐
Career Karma
careerkarma.com › blog › javascript › javascript sort array: a how-to guide
JavaScript Sort Array: A How-To Guide | Career Karma
December 1, 2023 - You can use the JavaScript sort() method to sort an array. The sort() method accepts an array as an argument and sorts its values in ascending order. Arrays are sorted in place which means the original array is modified.
🌐
YouTube
youtube.com › watch
How to Sort a String Array In JavaScript (Ascending and Descending Order) - YouTube
How to Sort a String Array In JavaScript (Simple)Greetings, in this quick Javascript tutorial, we shall be looking at how to sort String arrays in ascending ...
Published: March 17, 2023
🌐
ZetCode
zetcode.com › javascript › sort-array
JavaScript Array Sorting - Techniques and Examples
The built-in sort function sorts the elements of an array in place and returns the sorted array. It takes an optional compare function as a parameter. The function is used to determine the order of the elements. It returns a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. By default, numbers are sorted numerically in ascending order and strings lexically also in ascending order.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › toSorted
Array.prototype.toSorted() - JavaScript - MDN Web Docs
The toSorted() method of Array instances is the copying version of the sort() method. It returns a new array with the elements sorted in ascending order.
🌐
GeeksforGeeks
geeksforgeeks.org › 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.
Published: November 16, 2024
🌐
Mimo
mimo.org › glossary › javascript › sort
JavaScript Sort Method: Advanced Array Sorting Techniques
Default Sort is Alphabetical: If ... before 20). Always Use a Compare Function for Numbers: To sort numbers, you must use a compare function like (a, b) => a - b for ascending order or (a, b) => b - a for descending order....
🌐
LearnersBucket
learnersbucket.com › home › examples › javascript › sort a set in javascript in ascending or descending order
Sort a set in JavaScript in Ascending or Descending order - LearnersBucket
August 31, 2023 - The Array.sort() method, sorts the values depending upon the return value of the callback function. If the value is positive it will sort in ascending order.
🌐
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 - The sort() method can also sort ... an array. It can sort either alphabetic or numeric values. By default, the sort() method sorts the items in ascending order (up)....
🌐
W3Schools
w3schools.com › js › js_array_sort.asp
JavaScript Array Sort
ES2023 added the toSorted() method as a safe way to sort an array without altering the original array.