How to reverse items stored in variable before being used in foreach loop?
<p>I have a webpage that contains a few ASP.NET panels and JavaScript that is executed when the user clicks a button to expand and collapse the panels. I need to open the panels in the reverse order but using JavaScript reverse() doesn't appear to reverse the order of items stored in components (panels variable). </p>

<p>I have the following JavaScript:</p>

<pre><code>function expandCollapsePanels() 
{
    var collapse = $('#&lt;%= lbltogglePanels.ClientID %&gt;').html() == "Collapse all panels";
    var panels = Sys.Application.getComponents(); //adding .reverse() does not work

    for (var i in panels) 
    {
        panels[i].set_Collapsed(collapse);
    }
}
</code></pre>

<p>How can I modify the code above to do this?</p>
