Is there a more elegant way to add a field to JSON without using eval? My current solution works but is not very clean.
var json = {};
var id = "test";
eval("json." + id + " = 5;");
console.log(json.test);
UPDATE: Apologies for any confusion in my question. I am looking for a method that utilizes the value of the variable id for the new field.
Cheers, Bernhard