 <p>If you want to sort by the first number, the approach is:</p> <pre><code>var desire = ranges.sort(function(a,b){return parseInt(a)-parseInt(b)}); </code></pre> <p>Explanation: <code>parseInt(a)</code> just removes everything after the non-number, i.e. <code>-</code> and returns the number.</p> <p>If you also want to make it sort by the first number properly if you have ranges starting with the same numbers (i.e. <code>3-5</code> and <code>3-7</code>):</p> <pre><code>var desire = ranges.sort(function(a,b){ return (c=parseInt(a)-parseInt(b))?c:a.split('-')[1]-b.split('-')[1] }); </code></pre> <p>Explanation: works as the first one until the first numbers are equal; then it checks for the second numbers (thanks <a href="http://stackoverflow.com/users/1202830/michael-geary">Michael Geary</a> for idea!)</p> <p>If you want to sort by the result of equation, go for</p> <pre><code>var desire = ranges.sort(function(a,b){return eval(a)-eval(b)}); </code></pre> <p>Explanation: <code>eval(a)</code> just evaluates the expression and passes the result.</p> <p>Also, as <a href="http://stackoverflow.com/questions/34442270/sort-array-in-ascending-order/34442373#comment56626396_34442373">mentioned by h2ooooooo</a>, you can specify the radix to avoid unpredictable behavior (i.e. <code>parseInt(a, 10)</code>).</p>