Dynamically Forming a JSON object traversion without using eval.
- by Matt Willhite
Given I have the following: (which is dynamically generated and varies in length)
associations = ["employer", "address"];
Trying to traverse the JSON object, and wanting to form something like the following:
data.employer.address
or
data[associations[0]][association[1]]
Without doing this:
eval("data."+associations.join('.'));
Finally, I may be shunned for saying this, but is it okay to use eval in an instance like this? Just retrieving data.