How to sort an array of integers correctly How to sort an array of integers correctly javascript javascript

How to sort an array of integers correctly


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);