Accessing a JavaScript object property names with a "-" in it
Posted
by
Anil kumar
on Stack Overflow
See other posts from Stack Overflow
or by Anil kumar
Published on 2013-11-09T03:34:19Z
Indexed on
2013/11/09
3:53 UTC
Read the original article
Hit count: 245
JavaScript
|JSON
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.
© Stack Overflow or respective owner