JavaScript Sorting Arrays
Alpabetic Sort
- Array sort()
- Array reverse()
- Array toSorted()
- Array toReversed()
- Sorting Objects
Numeric Sort
- Numeric Sort
- Random Sort
- Math.min()
- Math.max()
- Home made Min()
- Home made Max()
Array sort()
The sort() method sorts an array alphabetically:
Example
const fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.sort();
Array reverse()
The reverse() method reverses the elements in an array:
Example
const fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.reverse();
Math.min()
You can use Math.min.apply to find the lowest number in an array:
Example
function myArrayMin(arr) { return Math.min.apply(null, arr); }
Math.max()
You can use Math.max.apply to find the highest number in an array: