开发者

How to pass an array into a map? Syntax

开发者 https://www.devze.com 2023-03-16 21:45 出处:网络
I need to do s开发者_StackOverflow中文版omething like this: $(\'#online-order\').wcForms({id: \'#online-order\', to: \'contact\', colors[\'red\']: \'#00F\' });

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

精彩评论

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