简体   繁体   中英

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. 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. Think of it as a group or collection of things in a thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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