0

How to sort the elements of an array in place in JavaScript

JavaScript
const months = ['March', 'Jan', 'Feb', 'Dec'];
months.sort();
console.log(months); // ["Dec", "Feb", "Jan", "March"]


// the array elements are converted to strings, then sorted according to each character's Unicode code point value.
const array1 = [1, 30, 4, 21, 100000];
array1.sort();
console.log(array1); // [1, 100000, 21, 30, 4]

RUN
add comment
Suggest a different solution or add another example