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

前端 未结 8 959
不思量自难忘°
不思量自难忘° 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:19

    There is no way to know that the two members of the options array came from variables named size and color.

    They are also not necessarily called that exclusively, any variable could also point to that array.

    var notSize = size;
    
    console.log(options[0]); // It is `size` or `notSize`?
    

    One thing you can do is use an object there instead...

    var options = {
        size: size,
        color: color
    }
    

    Then you could access options.size or options.color.

提交回复
热议问题