JS Variable inside another variable

Posted by Tusk on Stack Overflow See other posts from Stack Overflow or by Tusk
Published on 2012-10-27T16:38:21Z Indexed on 2012/10/27 17:00 UTC
Read the original article Hit count: 196

Filed under:
|

I have a function that would use other variables, depending on what has been passed.

Like this = ActionBar(slot) slot contains "one".

and I would like to create a call inside that like object.slot.name but it should convert it before hand to make the command look like object.one.name. Is there a way to do this in javascript/jquery?

I remember vaguely that some other language does this as {slot} or something like that.

Sorry if this question was already asked, I've checked google and stackoverflow too, but didn't find an answer.

Also I'd like to know what's the proper programming term for this kind of variable passing?

Edited it cause of misunderstandings. I'm looking into OOP js, so object is an object, one is an object, and name is an attribute, but when passing I'm passing "one" as a string to the function.

Tried eval, it doesn't work while dotted with an object.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery