I have a json object:
var config =
{
"data1" :
{
"emp1":
{
"phone" : "111",
"address": "xxx"
},
"emp2":
{
"phone" : "111",
"address": "xxx"
}
}
}
In my function I pass the root object and the string of the name I want:
function getEmp(config, section)
{
}
config is the json object above. Section is a string for either emp1 or emp2. I would like to be able to combine for example use the function like so
var emp1Data = getEmp(config, 'emp1')
What is the best way to return that portion of the JSON object?
Ive tried:
function getEmp(config, section)
{
return JSON.parse(config + '.' + emp);
}
but this fails. I would like to be able to do it without looping in the function.
Update 1 My config object has an extra comma. I have updated it
Update 2 I fixed my config object now