Answers for "how to sort a number array in javascript"

9

javascript sort by numerical value

// Sort an array of numbers based on numerical value.
let numbers = [23, 65, 88, 12, 45, 99, 2000]

let sortednumbers = numbers.sort((a, b) => a - b);
//=> [12, 23, 45, 65, 88, 99, 2000]
Posted by: Guest on February-28-2020
14

sorting array from highest to lowest javascript

// Sort an array of numbers 
let numbers = [5, 13, 1, 44, 32, 15, 500]

// Lowest to highest
let lowestToHighest = numbers.sort((a, b) => a - b);
//Output: [1,5,13,15,32,44,500]

//Highest to lowest
let highestToLowest = numbers.sort((a, b) => b-a);
//Output: [500,44,32,15,13,5,1]
Posted by: Guest on March-25-2020
3

sorting of arraray's number element in javascript

let numbers = [0, 1, 2, 3, 10, 20, 30];
numbers.sort((a, b) => a - b);

console.log(numbers);
Posted by: Guest on April-17-2020
0

Sort numbers in javascript

[0,10,4,9,123,54,1].sort((a,b) => a-b);>>> [0, 1, 4, 9, 10, 54, 123]
Posted by: Guest on August-26-2021
1

sort numbers in array javascript

function sortNumber(a, b) {
  return a - b;
}
Arr.sort(sortNumber);
Posted by: Guest on March-01-2020

Code answers related to "how to sort a number array in javascript"

Browse Popular Code Answers by Language