sort array of arrays javascript code example
Example 1: sort() function example JavaScript
function ascendingOrder(arr) {
return arr.sort(function(a, b) {
return a - b;
});
}
ascendingOrder([1, 5, 2, 3, 4]);
Example 2: JavaScript Sorting Arrays
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort(); // Sorts the elements of fruits
Example 3: sort array javascript
let numbers = [5, 2, 8, 1, 4, 6, 3, 7]
numbers.sort() // sorts the numbers ascending: [1, 2, 3, 4, 5, 6, 7, 8]