About 376,000 results
Open links in new tab
  1. javascript - How to sort an array of integers? - Stack Overflow

    Jun 30, 2009 · The accepted answer and equivalents like numArray.sort((a,b) => a - b) are great when the array contains only numbers without infinities or NaN. They can be extended to …

  2. 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.

  3. 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 …

  4. JavaScriptSort a Numeric Array - GeeksforGeeks

    Nov 16, 2024 · Here are some common methods to Sort Numeric Array using JavaScript. Please note that the sort function by default considers number arrays same as an array of stings and …

  5. JavaScript Array sort: Sorting an Array More Effectively

    This tutorial shows you how to use the JavaScript array sort method to sort arrays of numbers, strings, and objects.

  6. JavaScript Array sort() Method | CodeToFun

    Nov 20, 2024 · "Optimize your JavaScript code effortlessly with the powerful Array sort() method. Easily arrange elements in ascending or descending order, enhancing the efficiency of your …

  7. JavaScript Sort Array - How to Sort an Array Accurately

    Mar 14, 2023 · In this article, you will learn how to sort an array in JavaScript, some shortcomings associated with the sort() method, and how to get more accurate results. If you are in a rush, …

  8. How do I sort an array of numbers in Javascript? » Rad Devon

    In order to sort numbers, you’ll need to write a function that returns a negative number if a is less than b, returns a positive number if b is less than a, and returns 0 if the numbers are the same.

  9. Using JavaScript's sort Method for Sorting Arrays of Numbers

    Sep 4, 2020 · By default the sort() method sorts the array: To do this, the sort method calls the String() casting method on every array element and then compares the equivalent strings to …

  10. How to sort a javascript array of numbers - Stack Overflow

    Use a custom sort function. Here is a solution to sort a Javascript array in ascending order. code. function bubblesort(array){ var done = false; while(!done){ done = true; for(var i = 1; i< …

  11. Some results have been removed
Refresh