sort an array in ascending order by values themselves javascript code example
Example 1: sort by ascending javascript
const months = ['March', 'Jan', 'Feb', 'Dec'];
months.sort();
console.log(months);
// expected output: Array ["Dec", "Feb", "Jan", "March"]
Example 2: sort numbers in array javascript
function sortNumber(a, b) {
return a - b;
}
Arr.sort(sortNumber);