How do I parse a particular object value in an array of objects, object attribute having special characters:
var mycars = new Array();
var obj = {"x-h": "4", "y": "1"};
mycars.push(obj);
document.write(mycars[0].a-h + "<br>");
How do I parse a particular object value in an array of objects, object attribute having special characters:
var mycars = new Array();
var obj = {"x-h": "4", "y": "1"};
mycars.push(obj);
document.write(mycars[0].a-h + "<br>");
Access the property as follows (using quotes):
document.write(mycars[0]["x-h"] + "");
Also note that you were using "a-h" instead of "x-h".
Values can be retrieved from an object using brackets [ ] .
If your string expression is a legal JavaScript name and not a reserved word, then the "." notation can be used instead.
"x-h" is not a legal Javascript name. Instead you can use x_h , then you can use the "." notation access directly:
document.write(mycars[0].x_h + "");