开发者

How to pass an array into a map? Syntax

I need to do s开发者_StackOverflow中文版omething like this:

$('#online-order').wcForms({id: '#online-order', to: 'contact', colors['red']: '#00F' });

But there is mistake in syntax. Please, tell me how i must pass it. Thanks!


As Javascript has no associative arrays, if you want it that way, you need to use another object.

{id: '#online-order', to: 'contact', colors: { red: '#00F'} }

jsFiddle Demo

You can access your red property like this:

var obj = {id: '#online-order', to: 'contact', colors: { red: '#00F'} };

console.log(obj.colors.red);
//or
console.log(obj['colors']['red']);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜