I have a GeoJSON file that has fields of the days of the week like "Monday" with values 'Y' or 'N'. So I want to get today's day value, using something like
var theDayValue = 'feature.properties + day'
However this gives me a string. I want to get the value of
var theDayValue = feature.properties.Monday.
I plan on using this to show if open or closed in Leaflet by symbol color.
Answer
You could try using bracket notation instead of dot notation... you just have to give it the property name as a string (i.e., var theDayValue = feature.properties['Monday']). Assuming that 'day' is a variable whose value is the string matching the name of the field you want, that would look like this:
var day = 'Monday';
var theDayValue = feature.properties[day];
No comments:
Post a Comment