About 309,000 results
Open links in new tab
  1. JavaScript Array sort() Method - W3Schools

    The sort() method sorts the elements as strings in alphabetical and ascending order. The sort() method overwrites the original array.

  2. Sorting strings in descending order in Javascript (Most efficiently ...

    Aug 27, 2018 · The easiest way to revers the order of sorting is by swapping the operands. In ES2015 that's as easy as [b, a] = [a, b]. A full example: function compareWithOrder(a, b, shouldReverse = false) { if (shouldReverse) { [b, a] = [a, b] } return yourComparatorFn(a, b) }

  3. javascript - Using sort() to get numbers in descending order

    .sort((a, b) => b - a) // sort that array descending. .join('') // regroup all items in that array into 1 string. return parseInt(result) // turn the group of strings into an array. return +('' + n).split('').sort().reverse().join('');

  4. Array.prototype.sort() - JavaScript | MDN - MDN Web Docs

    Apr 3, 2025 · The sort() method of Array instances sorts the elements of an array in place and returns the reference to the same array, now sorted. The default sort order is ascending, built upon converting the elements into strings, then comparing their …

  5. Sort an Array of Strings in Descending order in JavaScript

    Mar 6, 2024 · To sort an array of strings in descending order, call the `sort ()` method on the array. Call the `reverse ()` method on the result.

  6. sorting an array in descending order in javascript without using …

    Aug 29, 2019 · I need to sort a simple array in descending order in javaScript without using a built-in method and it took me way too much time already... please help. for (var i = 1; i < array.length; i++) { var tmp = array[i]; for (var j = i - 1; j >= 0 && (array[j] < array[i]); j--) { array[j + 1] = array[j]; array[j + 1] = tmp; return array;

  7. How to Sort Data in Descending Using JavaScript - Delft Stack

    Mar 11, 2025 · Learn how to sort array data in descending order using JavaScript. This article covers default array methods and custom sorting functions, providing practical examples for numbers, strings, and objects.

  8. JavaScript’s sort() method: From basics to custom sorting

    Mar 7, 2025 · You can also sort it in descending order by modifying the compare callback. The sort() method mutates the original object and returns a reference to it. If you don’t want to mutate the original object, you can use the toSorted method similarly.

  9. How to sort the array elements in descending order in JavaScript

    Jul 21, 2022 · Different ways to sort the array elements in descending order in JavaScript. Learn how to reverse sort an array of numbers, array of characters and array of objects.

  10. JavaScript Array Sort - W3Schools

    By combining sort() and reverse(), you can sort an array in descending order: ES2023 added the toSorted() method as a safe way to sort an array without altering the original array.