Is it possible to use a string variable to reference an element in Javascript?
Posted
by somerandomguy
on Stack Overflow
See other posts from Stack Overflow
or by somerandomguy
Published on 2010-04-07T21:47:25Z
Indexed on
2010/04/07
21:53 UTC
Read the original article
Hit count: 175
Here's the quick version of the code as it stands right now:
function foo(attributeName, someJSObj, key, newValue)
{
someJSObj[key].attributeName = newValue;
}
Obviously this doesn't work, since it just creates a new element called attributeName. Is there an easy way to dereference the attributeName into the string that represents some existing attribute on someJSObj?
© Stack Overflow or respective owner