Sorting table using javascript sort()
<p>I am trying to sort a table.  I've seen several jQuery and JavaScript solutions which do this through various means, however, haven't seen any that use JavaScript's native sort() method.  Maybe I am wrong, but it seems to me that using sort() would be faster.</p>

<p>Below is my attempt, however, I am definitely missing something. Is what I am trying to do feasible, or should I abandon it?  Ideally, I would like to stay away from innerHTML and jQuery.  Thanks</p>

<pre><code>var index = 0; //Index to sort on.
var a = document.getElementById('myTable').rows;

//sort() doesn't work on collection
var b = [];
for (var i = a.length &gt;&gt;&gt; 0; i--;) {
    b[i] = a[i];
}

var x_td, y_td;

b.sort(function(x, y) {
    //Having to use getElementsByTagName is probably wrong
    x_td = x.getElementsByTagName('td')[index].data;
    y_td = y.getElementsByTagName('td')[index].data;
    return x_td == y_td ? 0 : (x_td &lt; y_td ? -1 : 1);
});
</code></pre>
