ordering a array in javascript code example
Example 1: how to sort an array by value in javascript
//ascending order
arr.sort(function(a, b){return a-b});
arr.sort((a, b) => a - b);
//descending order
arr.sort(function(a, b){return b - a});
arr.sort((a, b) => b - a);
Example 2: JavaScript Sorting Arrays
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort(); // Sorts the elements of fruits