Accessing a JavaScript object property names with a "-" in it
- by Anil kumar
I have a requirement to read JSON data in my application. Problem is that the JSON data that I am getting from the service includes "-" and when I am trying to read it, I am getting "Uncaught ReferenceError: person is not defined ". e.g.
I have below JSON object-
var JSONObject ={
"name-person":"John Johnson",
"street":"Oslo West 16",
"age":33,
"phone":"555 1234567"};
when I am writing below console log statement I am getting "Uncaught ReferenceError: person is not defined " error
console.log(JSONObject.name-person);
Can someone please help me how to read such data which includes "-" in it? I do not have control on the service and the DB so to modify source data is not in my hand.