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']);
精彩评论