wallabee
08-28-2003, 11:32 AM
seems hard to explain right now.
what i'm trying to do, as the title says, is pull an array entry and use it for the title of an array.
i have three arrays. one parent array that holds the names of the two child arrays.
var masterArray = new Array("squirrels", "chipmunks");
var squirrels = new Array;
squirrels["brown"] = 2;
squirrels["white"] = 6;
var chipmunks = new Array;
chipmunks["striped"] = 15;
chipmunks["spotted"] = 12;
my issue is this: by using a for loop, i can get "squirrels" and "chipmunks" to show up.
j = masterArray.length;
for (i=0; i<j; i++){
k = masterArray[i];
alert(k);
}
however, how do i take the resulting string "squirrels" and "chipmunks", and use them as the names of their own arrays so I can get to the numbers 2, 6, 15, or 12? i'd think like this:
function costCalc(location){
j = masterArray.length;
for (i=0; i<j; i++){
k = masterArray[i];
x = k.length;
for (i=0; i<x; i++){
alert(k[i])
}
}
}
this, apparently, isn't the right way? basically, i want k to turn into a string, so that when javascript sees "k[i]", it sees "chipmunk[i]" and not "masterArray[i][i]", so how do i do this? is the only answer nested arrays? do they even exist?
what i'm trying to do, as the title says, is pull an array entry and use it for the title of an array.
i have three arrays. one parent array that holds the names of the two child arrays.
var masterArray = new Array("squirrels", "chipmunks");
var squirrels = new Array;
squirrels["brown"] = 2;
squirrels["white"] = 6;
var chipmunks = new Array;
chipmunks["striped"] = 15;
chipmunks["spotted"] = 12;
my issue is this: by using a for loop, i can get "squirrels" and "chipmunks" to show up.
j = masterArray.length;
for (i=0; i<j; i++){
k = masterArray[i];
alert(k);
}
however, how do i take the resulting string "squirrels" and "chipmunks", and use them as the names of their own arrays so I can get to the numbers 2, 6, 15, or 12? i'd think like this:
function costCalc(location){
j = masterArray.length;
for (i=0; i<j; i++){
k = masterArray[i];
x = k.length;
for (i=0; i<x; i++){
alert(k[i])
}
}
}
this, apparently, isn't the right way? basically, i want k to turn into a string, so that when javascript sees "k[i]", it sees "chipmunk[i]" and not "masterArray[i][i]", so how do i do this? is the only answer nested arrays? do they even exist?