简体   繁体   English

您如何使javascript变量不只一件事?

[英]How do you make a javascript variable more than one thing?

There might have been an answer quite like the answer to this might be, but I did not know what terms to type in. So here is my question. 可能会有一个很像答案的答案,但是我不知道要输入什么术语。所以这是我的问题。 I am trying to make a javascript variable that equals more than one thing. 我正在尝试使一个JavaScript变量等于一件事。 This is what I think might work, but it does not work. 我认为这可能会起作用,但不起作用。 Here it is: 这里是:

var chars = [1-9]
}

That doesn't work, so does anyone know a solution? 那行不通,所以有人知道解决方案吗? If you can think of a way, it would be greatly appreciated. 如果您能想到一种方法,将不胜感激。

You can have an array: 您可以拥有一个数组:

var chars = [1, 2, 3, 4, 5, 6, 7, 8, 9];

Or an object: 或对象:

var chars = {
    thing1: 'foo',
    thing2: 'bar'
};

These can be considered as multiple things, as you can do chars.thing1 in my second example for instance, but really it's still one thing. 这些可以被认为是很多事情,例如您可以在第二个示例中执行chars.thing1 ,但实际上这仍然是一回事。 Think of it as a group or collection of things in a thing. 可以将其视为事物中的事物的集合或集合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM