Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
September 7th, 2008, 11:27 PM
|
#1 (permalink)
| | Junior Member
Join Date: Sep 2008
Posts: 18
| JavaScript -- for loop with a nested array
What I want to do is have one large array or 'table' and have each of the 160,000 'records' have about 5 'fields' each. Code: table = new Array();
table = [
record[0] = ["field1", "field2", "field3", "field4", "field5"];
record[1] = ["field6", "field7", "field8", "field4", "field9"];
record[2] = ["field10", "field11", "field12", "field13", "field14"];
record[3] = ["field15", "field16", "field17", "field18", "field19"];
record[4] = ["field20", "field21", "field22", "field23", "field24"];
]; I just wanted to know if this kind of thing was possible or even existed. I've been working too hard to actually think about this--been trying to figure out how for 2 weeks now--and I need help. The only days I have off are tomorrow and the day after, so if I could get a working draft by tomorrow morning I'd be saved! Filling the array won't be a problem at all... I'm working with a small company and their servers aren't incredible so we're trying to get this as much client-side as possible is why I'm trying to do this in JS. Otherwise I'd do this in ASP.NET or something similar. PLEASE HELP. If left to figure this out alone I'll figure it out the hour before I go back to work! :-P |
| |
September 8th, 2008, 11:29 PM
|
#2 (permalink)
| | Member
Join Date: Oct 2003
Posts: 247
|
Here is how you can do arrays of arrays. You could also use a multidem. array but here is exactly what you want. Code: var pets = new Array ( );
pets[0] = new Array ( "Sheba", 13, "cat" );
pets[1] = new Array ( "Jasper", 12, "dog" );
alert ( pets[0][0] + " is a " + pets[0][1] + " year old " + pets[0][2] ); // Displays "Sheba is a 13 year old cat"
alert ( pets[1][0] + " is a " + pets[1][1] + " year old " + pets[1][2] ); // Displays "Jasper is a 12 year old dog" |
| |
September 8th, 2008, 11:31 PM
|
#3 (permalink)
| | Junior Member
Join Date: Sep 2008
Posts: 18
|
Thanks :-)
I'll learn what I need from that. It's for a game I play online, I'm making an online map... big horrible mess. Oh well. Time to get everyone else to collect the information for me >:-) |
| |
September 8th, 2008, 11:36 PM
|
#4 (permalink)
| | Junior Member
Join Date: Sep 2008
Posts: 18
|
Oh and technically speaking JavaScript doesn't support multi-dimensional arrays, I've just never had the need to nest arrays like this and wasn't sure of the syntax. I tried looking it up earlier, but forgot what it was... guess all I needed was a pair of fresh eyes! Thanks :-) |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |