A
Andrew Poulos
If I have an array whose elements may or may not also be arrays and I’m
given a string that relates to an appropriate index in that array how do
I use that string as the index? For example, if I have an array that
looks like this:
myArray = [[0,1],[2,3]];
and a string that looks like:
str = “1_1”;
I can do this to the string:
foo = str.split(“_”); // foo now equals [“1”,”1”]
Then how can I use foo as an index? That is, something like
bar = myArray[foo]; // bar should now equal 3
and it's sibling
myArray[foo] = 1;
I've managed something using a FOR loop and eval but it seems such a
hack. And the problem is complicated by the fact that the array may have
as many levels of nested arrays as the user creates.
Andrew Poulos
given a string that relates to an appropriate index in that array how do
I use that string as the index? For example, if I have an array that
looks like this:
myArray = [[0,1],[2,3]];
and a string that looks like:
str = “1_1”;
I can do this to the string:
foo = str.split(“_”); // foo now equals [“1”,”1”]
Then how can I use foo as an index? That is, something like
bar = myArray[foo]; // bar should now equal 3
and it's sibling
myArray[foo] = 1;
I've managed something using a FOR loop and eval but it seems such a
hack. And the problem is complicated by the fact that the array may have
as many levels of nested arrays as the user creates.
Andrew Poulos