Javascript Array inside Array - how can I call the child array name?

前端 未结 8 913
不思量自难忘°
不思量自难忘° 2020-12-24 13:42

Here is the example of what I am doing:

   var size = new Array("S", "M", "L", "XL", "XXL");
   var color =          


        
8条回答
  •  隐瞒了意图╮
    2020-12-24 14:28

    You've made an array of arrays (multidimensional), so options[0] in this case is the size array. you need to reference the first element of the child, which for you is: options[0][0].

    If you wanted to loop through all entries you can use the for .. in ... syntax which is described here.

    var a = [1,2,4,5,120,12];
    for (var val in t) {
        console.log(t[val]);
    }
    
    var b = ['S','M','L'];
    var both = [a,b];
    
    for (var val in both) {
         for(val2 in both[val]){console.log(both[val][val2])}
    }
    

提交回复
热议问题