这是我正在做的事的例子:
Here is the example of what I am doing:
var size = new Array("S", "M", "L", "XL", "XXL"); var color = new Array("Red", "Blue", "Green", "White", "Black"); var options = new Array( size, color);我正在做一个循环选择形式的事情,效果很好,但是在这种情况下,我想获取Array子名称-大小或颜色.当我做alert(options [0])时,我得到了数组的整个元素.但是对于某些特定情况,我只想获取数组名,就像我已经说过的那样,它是大小/颜色.有办法实现吗?
I am doing a loop select form thingies which work good, but I want to fetch the Array child name, in this case - size or color. When I am doing alert(options[0]), I get the whole elements of array. But for some specific case, I want to get only the array name, which is size/color like I have said already. Is there way to achieve that?
推荐答案我会创建一个像这样的对象:
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));要单独访问密钥:
for (var key in options) { alert(key); }P.S .:创建新数组对象时,请勿使用 new Array ,而应使用 [] .
P.S.: when you create a new array object do not use new Array use [] instead.
更多推荐
数组内的Javascript数组
发布评论