I’m having trouble accessing a particular object using a variable in javascript. Here’s the code I’m working with:
global_grouplist = getTenantGroupList();
console.log(global_grouplist)
var currentgroup = getSelectedGroupName();
console.log(currentgroup)
console.log(global_grouplist.currentgroup);
‘global_grouplist’ returns a large array of objects, and I want to get a particular value from there. If I take the value that currentgroup will equal, and run it like this:
console.log(global_grouplist.actualvalue)
It gives me what I want. However, when I do this.
var currentgroup = actualvalue
console.log(global_grouplist.currentgroup)
This is the getTenantGroupList() function:
function getTenantGroupList(){
return jQuery.parseJSON($.ajax({
url: 'tenantgrouplist.json',
dataType: 'json',
async: false
}).responseText);
}
And here is the getSelectedGroupName function:
function getSelectedGroupName(){
var retval = null;
$('#grouplist li a').each(function(){
if($(this).parent().hasClass('group-selected'))
retval=$(this).html();
});
return retval;
}
It does not work. Is there something fundamental I’m missing here? If you need more information, please let me know!
To access the properties in this manner you need to use array notation. Try this: