Javascript expression to define object's property name?
Posted
by Kirzilla
on Stack Overflow
See other posts from Stack Overflow
or by Kirzilla
Published on 2010-05-18T08:09:00Z
Indexed on
2010/05/18
8:10 UTC
Read the original article
Hit count: 322
JavaScript
Hello,
I'd like to create this object...
object = {
'object[1][var_name_1]' : 'value1',
'object[1][var_name_2]' : 'value2',
};
I'm trying to it this way, but I'm getting error missing : after property id...
function getPrefix() {
return 'object[1]';
}
object = {
getPrefix() + '[var_name_1]' : 'value1',
getPrefix() + '[var_name_2]' : 'value2',
}
What am I doing wrong? Or maybbe it is impossible to set object property name using js experession?
Thank you
© Stack Overflow or respective owner