Ax.
Ax.

Reputation: 320

How to pass an array into a map? Syntax

I need to do something 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!

Upvotes: 1

Views: 190

Answers (1)

kapa
kapa

Reputation: 78681

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']);

Upvotes: 3

Related Questions