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

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

    I would create an object like this:

    var options = { 
        size: ["S", "M", "L", "XL", "XXL"],
        color: ["Red", "Blue", "Green", "White", "Black"]
    };
    
    
    alert(Object.keys(options));
    

    To access the keys individualy:

    for (var key in options) {
        alert(key);
    }
    

    P.S.: when you create a new array object do not use new Array use [] instead.

提交回复
热议问题