Sorts the elements of an array in place.
Syntax
arr.sort(compareFn?)Example
Enter values below to update the example in real time.
const→numbers→sort→console→const numbers = [3, 1, 4, 1, 5, 9];
numbers.sort((a, b) => a - b);
console.log(numbers); // [1, 1, 3, 4, 5, 9]