È difficile spiegare il caso a parole, lasciatemi fare un esempio:
var myObj = {
'name': 'Umut',
'age' : 34
};
var prop = 'name';
var value = 'Onur';
myObj[name] = value; // This does not work
eval('myObj.' + name) = value; //Bad coding ;)
Come posso impostare una proprietà variabile con valore variabile in un oggetto JavaScript?
myObj[prop] = value;. eval('myObj.'+name)non funziona neanche in quanto la variabile namenon esiste.
vartastiere per dichiarare le variabili, usare più punti e virgola, non usare evale accettare più risposte. Fatto.
myObj[name]" quando sono abbastanza sicuro che volevi scrivere " myObj[prop]".