Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i sort an array a certain way with characters and numbers in javascript?
    primarykey
    data
    text
    <p>I want to sort array like this:</p> <pre><code>["AAAA1", "AAAA3", "ABAA2", "AAAA10", "AAAA100", "BBB2", "BBB10", "BBAA3", "BBB2AA"] </code></pre> <p>when i sort it, returns me like:</p> <pre><code>["AAAA1", "AAAA10", "AAAA100", "AAAA3", "ABAA2", "BBAA3", "BBB10", "BBB2", "BBB2AA"] </code></pre> <p>That i like to sort it like this:</p> <pre><code>["AAAA1", "AAAA3", "AAAA10", "AAAA100", "ABAA2", "BBAA3", "BBB2", "BBB2AA", "BBB10"] </code></pre> <p>so i searched it in stackoverflow and i found something like under links but all of that haven`t general method for sorting characters &amp; numbers string and only works for special questions!!</p> <p><a href="https://stackoverflow.com/questions/9611304/javascript-sort-an-array-a-certain-way-with-integers-and-characters">javascript: sort an array a certain way with integers and characters</a></p> <p><a href="https://stackoverflow.com/questions/4576903/how-to-sort-number-in-javascript-sort-method">How to sort number in javascript sort method</a></p> <p><a href="https://stackoverflow.com/questions/1063007/sort-not-working-with-integers">How to sort an array of integers correctly</a></p> <p><strong>Edit1:</strong></p> <p>Please check answers of questions in <a href="https://stackoverflow.com/questions/3108530/sort-javascript-string-array-containing-numbers">Sort JavaScript String Array containing numbers</a>, the answer works with text with format var <code>regex = /Value\s([0-9]+)/;</code> and or in <a href="https://stackoverflow.com/questions/4340227/sort-mixed-alpha-numeric-array">Sort mixed alpha/numeric array</a> the answer only works with one character at the beginning of the string.. that i need some method works with all possible string that contains characters and numbers ...!!</p> <p><strong>Edit2:</strong></p> <p>Tanx Felix Kling:</p> <p><strong>i`m so sorry, i have wrong order to array in example, so i liked to BBB2AA order before BBB10</strong></p> <p>I found the general method for doing that with add leading zero, i wrote a version of it now and please optimize it or give me another options for sorting like that <a href="http://jsfiddle.net/Qd8nd/" rel="nofollow noreferrer">http://jsfiddle.net/Qd8nd/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload