Javascript Logo

Javascript Sort Method

Here's how to sort (and reverse sort) an array of values.

USAGE: Copy and paste the code samples below into the Javascript console in your browser, then simply hit return on your keyboard to see the code in action.

//sort actually sorts the values in 
//an array, typical usage is to assign 
//incoming values as "a" and "b"
const ages = 
const agesSort = ages.sort((a,b) => a-b);

//reverse works nicely too
const agesRev = ages.reverse();