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
  • 6,295
  • 19
  • 80
  • 150

1 Answers1

0

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

return customContext[query];
dave
  • 62,300
  • 5
  • 72
  • 93