Hi –
I have existing JSON object on the page and I’m trying to call a value from the object using a function:
[CODE]
var DDO = {};
DDO.specVersion = “10-1-2014”
DDO.navData = {
“home”:”Home Page”,
“news”:”News”,
“music”:”Music”,
“video”:”Video”,
“shop”:”Shop”,
“tour”:”Tour”,
“fanwall”:”Fan Wall”,
“social”:”Social”
};
I have a simple function designed to return any value of the object:
[CODE]
function grab_navData(elm)
{
var navElement = DDO.navData.elm;
return navElement;
}
I call the function like so:
[CODE]
grab_navData(‘social’);
Running this function returns no errors but returns undefined – instead of the value of “Social” like I would expect. And if I choose to write out the direct path to the element as a test
[CODE]
var navElement = DDO.navData.social;
the code returns as expected.
I’m trying to figure out if this is a scope issue inside the object or if I need to convert the value of (elm) to an object first.
Any ideas would be helpful.
Thanks