jQuery - Sorting an array?
<p>I'm using Ajax to get some XML, and then filling in some fields on a form with the results. There is a numerical field on the form and I would like to sort the results by this number (highest first). </p>

<p>How would I go about doing this in jQuery?</p>

<p>My js function code is currently:</p>

<pre><code>function linkCounts() {
    ws_url = "http://archreport.example.co.uk/worker.php?query=linkcounts&amp;domain="+$('#hidden_the_domain').val();
    $.ajax({
        type: "GET",
        url: ws_url,
        dataType: "xml",
        success: function(xmlIn){
            results = xmlIn.getElementsByTagName("URL");
            for ( var i = 0; i &lt; results.length; i++ ) {
                $("#tb_domain_linkcount_url_"+(i+1)).val($(results[i].getElementsByTagName("Page")).text());
                $("#tb_domain_linkcount_num_"+(i+1)).val($(results[i].getElementsByTagName("Links")).text());
            }
            $('#img_linkcount_worked').attr("src","/images/worked.jpg");
        },
        error: function(){$('#img_linkcount_worked').attr("src","/images/failed.jpg");}
    });
}
</code></pre>

<p>The <code>Links</code> tag is the one I'm wanting to sort it on.</p>

<p>Thanks</p>

<p>For reference the XML that's getting returned is like the following:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
&lt;Response&gt;
  &lt;ResponseCode&gt;1&lt;/ResponseCode&gt;
  &lt;ResponseStatus&gt;OK&lt;/ResponseStatus&gt;
  &lt;ReportId&gt;2&lt;/ReportId&gt;
  &lt;UrlChecked /&gt;
  &lt;MaxLinks&gt;75&lt;/MaxLinks&gt;
  &lt;PagesFound&gt;121&lt;/PagesFound&gt;

  &lt;URLs&gt;
&lt;URL&gt;
      &lt;Page&gt;http://www.example.co.uk/blog&lt;/Page&gt;
      &lt;Links&gt;78&lt;/Links&gt;
    &lt;/URL&gt;
    &lt;URL&gt;
      &lt;Page&gt;http://www.example.co.uk/blog/&lt;/Page&gt;

      &lt;Links&gt;78&lt;/Links&gt;
    &lt;/URL&gt;
    &lt;URL&gt;
      &lt;Page&gt;http://www.example.co.uk/blog/author/example/&lt;/Page&gt;
      &lt;Links&gt;78&lt;/Links&gt;
    &lt;/URL&gt;
    &lt;URL&gt;

      &lt;Page&gt;http://www.example.co.uk/blog/author/example/page/2/&lt;/Page&gt;
      &lt;Links&gt;78&lt;/Links&gt;
    &lt;/URL&gt;
&lt;/URLS&gt;
&lt;/Response&gt;
</code></pre>
