I display the content of the array in a table.
Then I have a link which lets the user sort the table. I do that by sorting the array, delete the content of the table and then redisplay the content of the array. But the "for (var i in obj)" seems to use the original order. I can see in firebug that the array is properly sorted. So why does it maintain the original sort order?
Here is my sample code and below is a screen shot of the array after sorting;
Expand|Select|Wrap|Line Numbers
- function a7DayKeysSort()
- {
- /*
- -----------------------------------------
- clear previous values
- but preserve the header line
- -----------------------------------------
- */
- var tr, td
- tbody = document.getElementById("dJobLines");
- while (tbody.rows.length > 1)
- {
- tbody.deleteRow(1);
- }
- /*
- --------------------------------
- sort content of array
- --------------------------------
- */
- a7DayKeys.sort();
- /*
- ----------------------------------------------
- now re-display content of array
- ----------------------------------------------
- */
- for ( var ix in a7DayKeys )
- {
- cKey = a7DayKeys[ix];
- tr = tbody.insertRow(tbody.rows.length);
- td = tr.insertCell(tr.cells.length);
- td.setAttribute("align", "center");
- td.innerHTML = cKey.pJob;
- td = tr.insertCell(tr.cells.length);
- td.innerHTML = cKey.pName;
- td = tr.insertCell(tr.cells.length);
- td.setAttribute("align", "center");
- td.innerHTML = cKey.pPC;
- //load check boxes for true values
- for (var nx = 0; nx < 7; nx++ )
- {
- td = tr.insertCell(tr.cells.length);
- td.setAttribute("align", "center");
- if ( cKey[nx] == true )
- {
- td.innerHTML = '<INPUT TYPE="checkbox" NAME="">';
- }else{
- td.innerHTML = " ";
- }
- }
- }
- }