I am trying to use the value from a select dropdown list as a variable for a Json filtering function. When I hardcode the value of a.(name), it works, but when I try to use the keyname var from the dropdown list it returns undefined.
function sortJson(a, b)
{
//get sorting dropdown value for key
var keyname = $('#sortByKey').val();// I want to dynamically set the keyname from dropdown. It traces correctly, so I am getting the value I want.
if (a.keyname == b.keyname)//works when i hardcode a.name, or a.id etc...
{
return 0;
}
return a.keyname > b.keyname ? 1 : -1;
};