javascriptobject-properties

Help needed with Javascript Objects


I need some help with Javascript objects. This is what I've got:

_genre_id = {politics:'1',sport:'2',celeb:'3',gossip:'4',busi:'5'};
var genre = 'politics';

What I want to accomplish would be to simply get the value stored for politics, in this case 1 by doing something like this:

var genreID = _genre_id.genre;

But this of course doesn't work because the genre property doesn't exist. I want it to relate to _genre_id.politics.

Any ideas would be welcome.


Solution

  • How about _genre_id[genre]?