OneCompiler

[JavaScript] How to sort an array?

I want to sort an array based on the elements, how can I do that in Javascript?

1 Answer

4 years ago by

Use sort method like below to sort the elements of an array

let numbers = [ 1 , 9, 3, 7, 2, 5 ];
console.log(numbers.sort());
4 years ago by Meera