333qaz333
12-30-2007, 03:56 AM
hi,
I will try to explain what I am trying to do as best as I can, however I think it will be much easier to follow along if you can see a demo.
Click here (http://333qaz333.no-ip.biz/test3.php) to view the demo.
Okay, so I am trying to work with arrays.
var a = new Array('a1', 'a2');
a['a1'] = 'a1value';
a['a2'] = 'a2value';
var b = new Array('b1', 'b2');
b['b1'] = 'b1value';
b['b2'] = 'b2value';
var ab = new Array(a, b);
When I try to access the array directly, I get the associative name ('a1', 'a2', 'b1', or 'b2') not the value ('a1value', 'a2value', 'b1value', 'b2value').
alert('Value of ab[0][1]:\n\n' + ab[0][1]);
//should return 'a2value', but instead it returns 'a2'.
At first I thought I was trying to store the value into the variable incorrectly.
However, when I use for(value in array) loops, I get the associative name half the time, but the other half the time I can actually get the value. This means that the value is in the variable, but I don't know how to properly retrieve it.
Here are my for loops:
for(value1 in ab){
for(value2 in ab[value1]){
alert(ab[value1][value2]);
}
}
Another question, why is my second for loop looping 4 times through an array that only has a length of 2?
This is very confusing, and I don't understand what is happening...
Again, here is the demo (http://333qaz333.no-ip.biz/test3.php) to show you what I am trying to do.
Any help is greatly appreciated!!!
~Brandon
I will try to explain what I am trying to do as best as I can, however I think it will be much easier to follow along if you can see a demo.
Click here (http://333qaz333.no-ip.biz/test3.php) to view the demo.
Okay, so I am trying to work with arrays.
var a = new Array('a1', 'a2');
a['a1'] = 'a1value';
a['a2'] = 'a2value';
var b = new Array('b1', 'b2');
b['b1'] = 'b1value';
b['b2'] = 'b2value';
var ab = new Array(a, b);
When I try to access the array directly, I get the associative name ('a1', 'a2', 'b1', or 'b2') not the value ('a1value', 'a2value', 'b1value', 'b2value').
alert('Value of ab[0][1]:\n\n' + ab[0][1]);
//should return 'a2value', but instead it returns 'a2'.
At first I thought I was trying to store the value into the variable incorrectly.
However, when I use for(value in array) loops, I get the associative name half the time, but the other half the time I can actually get the value. This means that the value is in the variable, but I don't know how to properly retrieve it.
Here are my for loops:
for(value1 in ab){
for(value2 in ab[value1]){
alert(ab[value1][value2]);
}
}
Another question, why is my second for loop looping 4 times through an array that only has a length of 2?
This is very confusing, and I don't understand what is happening...
Again, here is the demo (http://333qaz333.no-ip.biz/test3.php) to show you what I am trying to do.
Any help is greatly appreciated!!!
~Brandon