数组内的Javascript数组

编程入门 行业动态 更新时间:2024-10-23 01:40:13
本文介绍了数组内的Javascript数组-如何调用子数组名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我正在做的事的例子:

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数组

本文发布于:2023-07-28 02:38:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1226531.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   Javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!