Answers for "sort by array javascript"

54

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

javascript sort by id

elems.sort((a, b) => a.id - b.id);
Posted by: Guest on June-17-2020
0

js sort array

// Functionless
sort()

// Arrow function
sort((firstEl, secondEl) => { ... } )

// Compare function
sort(compareFn)

// Inline compare function
sort(function compareFn(firstEl, secondEl) { ... })
Posted by: Guest on October-07-2021

Code answers related to "sort by array javascript"

Browse Popular Code Answers by Language