sehummel
sehummel

Reputation: 5568

Associative arrays in Jquery

If I have an associative array like this:

var names = { '10watt' : '_ULR', '20watt' : '_ULR', '30watt' : '_ULR', '40watt' : '_ULR', '50watt' : '_ULR', '60watt' : '_ULR', '75watt' : '_ULR', '100watt' : 'ULCR', '120watt' : 'ULCR', '150watt' : 'ULCR' };

how do I write the value of the key to the browser, if the key is this.id?

I tried this but it didn't work (#name is the div I want to put the text in:

$('#name').text(names(this.id));

Upvotes: 3

Views: 237

Answers (1)

glebm
glebm

Reputation: 21130

$('#name').text(names[this.id])

This is not related to jQuery in any way though. In JavaScript, if you have an object obj, then you can access its property prop either like this obj.prop, or like this obj["prop"].

Upvotes: 4

Related Questions