Reputation: 131
Normally, we access json object elements using dot notation i.e. var obj = {"key": "value"}; var val = obj.key;
. How do we access the value in case of var obj = {"key-with-hyphens": "value"};
? Do I have to revert to [] i.e. var val = obj['key-with-hyphens'];
?
Upvotes: 3
Views: 6620
Reputation: 2009
> var obj = {"key-with-hyphens": "value"};
> obj["key-with-hyphens"];
< "value"
Upvotes: 4
Reputation: 5126
You can access it with this notation:
var val = obj["key-with-hyphens"];
Upvotes: 9