HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

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:

Example

function myArrayMax(arr) {
  return Math.max.apply(null, arr);
}
You can click on above box to edit the code and run again.

Output