I've got a pretty simple question (and tentative answers), I just want to see if maybe there is a better answer out there.
How can you access an object member in javascript when the member identifier is stored in another variable? Example:
state = 'sync';
messages = {
'sync': 'asdf',
'ready': 'asdf',
'complete': 'asdf'
};
Possibilities:
1. message = eval('messages.' + state);
- turn message into a hash (in prototype or jquery--not sure about jquery) and access through the framework's method
What other ways are there? Anything cleaner? In php it would be simple $message = $messages->$sync
.
I'm sure this question has been answered many times but it is tough to search for... all I get are eval responses when I search for 'variable variables'
Thanks