0

I have to sort cell names like this :

A1
A2
A3
A10

What I tried with this wrong order :

A1
A10
A2
A3

Code :

var cells = [ 'A1' 'A10', 'A2', 'A3' ];

function mysort(a,b) {
    return a.substr(0,1) - b.substr(0,1) && a.substr(1) - b.substr(1);
}

cells = cells.sort(mysort);

or

cells = cells.sort();

Any clue ?

  • How about you try to extract numeric part, treat it as number and then try sorting? – Rajesh Aug 28 '18 at 11:23
  • 1
    Probably a better duplicate: [How to sort strings in JavaScript](https://stackoverflow.com/questions/51165/how-to-sort-strings-in-javascript) (At least one with easier to read answers and much more upvotes on the question) – feeela Aug 28 '18 at 11:35

0 Answers0