Reputation: 43569
var ageRanges;
ageRanges = {
'18.20': 0,
'21.24': 0,
'25.34': 0,
'35.44': 0,
'45.54': 0,
'55.64': 0,
'65+': 0
};
I want to access ageRanges.'18.20'
, but that gives me an error: TypeError: Cannot read property '0' of null
- so what's the proper way to access it?
Upvotes: 0
Views: 147
Reputation: 2321
Use ageRanges['18.20']
to access the property. This is one of two ways to access JavaScript object properties. The alternative and recommended way is dot-notation, which fails in this instance due to the period character in your property names.
Upvotes: 3