Jump to content

reverse()


layton
 Share

Recommended Posts

I'm having a problem getting reverse() to reverse correctly. As it stands I have an array with 21 members. when I use reverse() on the array, at spots 10 and 21 they are placed at the bottom rather than in their normal order. I was under the assumption that reverse() is supposed to reverse the order, not rearrange the order.here's the code:

function myJobs(dateIn,task,url,dateOut){this.dateIn = dateIn;this.task = task;this.url = url;this.dateOut = dateOut;}theJobs = new Array();theJobs[01] = new myJobs("06.26.06","task1","my.url","06.26.06");theJobs[02] = new myJobs("06.26.06","task2","my.url","06.26.06");......theJobs[21] = new myJobs("06.26.06","task21","my.url","06.26.06");

further down i open a table, loop through the array, then close the table. here's the loop:

for(i in theJobs){document.write('<tr><td>'+theJobs[i].dateIn+'</td><td>'+theJobs[i].task+'</td><td>'+theJobs[i].url+'</a> </td><td>'+theJobs[i].dateOut+'</td></tr>');}

the idea behind this is to sort everything by date. newest date first. it's a glorified honey-do list. LOL. since i'm constantly adding new entries....it seems like a good idea to just reverse the order....but that's the problem. If there is a way better way to do this.....by all means...tell me. I'm not an expert.

Link to comment
Share on other sites

Not quite sure what you mean?

<script>var myArray = [];myArray[0] = "something0";myArray[1] = "something1";myArray[2] = "something2";myArray[3] = "something3";myArray[4] = "something4";myArray[5] = "something5";myArray[6] = "something6";myArray[7] = "something7";myArray[8] = "something8";myArray[9] = "something9";myArray[10] = "something10";myArray[11] = "something11";myArray[12] = "something12";myArray[13] = "something13";myArray[14] = "something14";myArray[15] = "something15";myArray[16] = "something16";myArray[17] = "something17";myArray[18] = "something18";myArray[19] = "something19";myArray[20] = "something20";myArray[21] = "something21";myArray = myArray.reverse();for(i in myArray){ document.write (myArray[i] + "<br />");}</script>

Reverses it fine for me...?Edit: yes, that would have been your problem :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...