Skip to content

Instantly share code, notes, and snippets.

@masautt
Last active September 3, 2019 22:59
Show Gist options
  • Save masautt/fe73908d0ccdde9a3e6df98ea884f108 to your computer and use it in GitHub Desktop.
Save masautt/fe73908d0ccdde9a3e6df98ea884f108 to your computer and use it in GitHub Desktop.
How to sort array in JavaScript?
var arr = ["7", "2", "5", "9"];
// Sort in ascending order?
arr.sort(); // --> 2,5,7,9
// Descending order?
arr.reverse(); // --> 9,7,5,2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment