Search code examples
javascriptarrayssortingnumericalphabetical

How to sort arrays numerically and alphabetically at the same time in JavaScript in this code, please


I'm trying so hard to sort these arrays numerically and alphabetically, except that it only sorts them based on their length only (especially numbers). Please help...

Tips: Open in IDE and click on the arrow or on the top of the table to sort them, then click again if arrow is pointing down. Cheers...


Solution

  • Have you considered doing a nested sort. for example doing something like:

     myArray = myArray.sort((a,b) => a[column] < b[column] ? 1 : -1).sort((a,b)=>a[newcolumn] - b [newvolumn])