0

How come the first alert shows Dublin but the second is undefined?

http://jsfiddle.net/pzdx6L5a/1/

function getRenderParamValue(query){
    customContext = JSON.parse("{\"test\":true,\"geo\":\"\",\"city\":\"Dublin\",\"categoryId\":\"\",\"categoryName\":\"\",\"productId\":\"\"}");
    alert(customContext.city);
    return customContext.query;
}

alert('city: ' + getRenderParamValue('city'));
bobbyrne01
  • 5,926
  • 14
  • 70
  • 139

1 Answers1

0

It's looking for a property 'query', which doesn't exist. Use [] instead of .:

return customContext[query];
dave
  • 57,127
  • 4
  • 69
  • 87