JavaScript对象中的数组? [英] Array inside a JavaScript Object?
本文介绍了JavaScript对象中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过看看这是否可行,但我找不到答案。
I've tried looking to see if this is possible, but I can't find my answer.
我正在努力让以下工作:
I'm trying to get the following to work:
var defaults = {
'background-color': '#000',
color: '#fff',
weekdays: {['sun','mon','tue','wed','thu','fri','sat']}
};
它只是给出了一个错误,我尝试使用({。 ..})
和 [{...}]
我希望能够使用以下内容访问工作日:
It just gives an error, and I've tried using ({...})
and [{...}]
I'd like to be able to access the weekdays using something like:
defaults.weekdays[0];
这可能吗?
推荐答案
杀掉大括号。
var defaults = {
backgroundcolor: '#000',
color: '#fff',
weekdays: ['sun','mon','tue','wed','thu','fri','sat']
};
这篇关于JavaScript对象中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文