In the example below is there a way to set one or more of the object keys for instance "value" to a variable? I would like to do this while keeping the JOSN object intact.
var ex = {
"value": 4,
"amount": 1341,
"data": "tree",
"animal": "mouse"
}
I know that it is possible to do this.
var value = "value";
var ex = {};
ex[value] = 4;
ex.amount = 1341;
ex.data = "tree";
ex.animal = "mouse";
This is tearing the whole object into pieces and is much harder to manage.
Nope, that’s not possible. You need to do it the second way, or a mixture of the two: