Sorting an Array Alphabetically using the sort Method
The sortmethod sorts the elements of an array according to the callback function. For example: function ascendingOrder(arr) { return arr.sort(function(a, b) { return a - b; }); } ascendingOrder([1, 5, 2, 3, 4]); // This would return the value [1, 2, 3, 4, 5]. Enter fullscreen mode Exit fullscreen mode function reverseAlpha(arr) {