views:

51

answers:

2

Hi guys. I have a javascript array that looks like this:

'40x27'  => array(  
    '1' => 0  
    '1.5' => 2  
    '2' = 1  
)  
'36x24' => array(   
    '1' => 1  
    '1.5' => 1  
    '2' = 2
)

etc.

I want to print out the values of the inner array like this:

i = 0;
for (i in outerArray){
    var k = 0;
    for (k in innerArray){
        alert(innerArray[k]);
    }//for
}//for

The issue I am having is that the k variable has the value of outerArray[i] instead of the key of the innerArray like so:

i=0;k="40x27";  
i=0;k="36x24";  
i=1;k="40x27";  
i=1;k="36x24";

Edit: sorry I forgot to include some code.

var outerArrays=new Array("40x27","36x24");
var innerArray=new Array("1","1.5","2");

+1  A: 

You aren't setting innerArray to anything. Try this:

for (var i in outerArray) {
    var innerArray = outerArray[i];
    for (var k in innerArray) {
        alert(innerArray[k]);
    }
}

BTW, these are not typically called arrays in Javascript like they are in PHP. Arrays in Javascript are sequences, while objects are maps from strings to arbitrary types like in this case.

Max Shawabkeh
A: 

Thanks for all of the pointers, once i took a look at how I created the arrays I realized that i had a dumb syntax error:

for (i in outerArray){
var k = 0;
for(k in innerArray[outerArray[i]]){
alert(innerArray[k]);
}//for }//for

thanks! you guys rock.

BFTrick