Answers for "sort on an array javascript"

25

JS array sort

numArray.sort((a, b) => a - b); // For ascending sort
numArray.sort((a, b) => b - a); // For descending sort
Posted by: Guest on May-08-2021
-1

sort() function example JavaScript

function ascendingOrder(arr) {
  return arr.sort(function(a, b) {
    return a - b;
  });
}
ascendingOrder([1, 5, 2, 3, 4]);
Posted by: Guest on April-24-2021
-1

javascript sort

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();
Posted by: Guest on February-09-2020
-3

mdn array sort

arr.sort([compareFunction])
Posted by: Guest on November-05-2020

Code answers related to "sort on an array javascript"

Browse Popular Code Answers by Language