I have a javascript object which I want to access by a dynamic variable:
var color = {
red : '#ff0000',
black : '#000000',
silver : '#7d8989'
};
var currentColor = $(val).html();
console.log(color[currentColor]);
But I get undefined message by the console. How can I access the data?
EDIT:
Problem was that the option value had whitespace at its end, thanks everyone for fast reply:
var currentColor = $.trim($(val).html());