I receive polygons via the ESRI REST API with Leaflet. I want to iterate through all attributes of a feature in order to create a custom pop-up for it.
My code looks like this:
myLayer.on('click', function (evt)
{
feature = evt.layer.feature;
//Here I want to iterate ...
}
I know that I can access the attributes like this:
feature.properties.myAttribute
But how can I iterate through all attributes?
Best Answer
If my understanding is correct, you want to read all properties of the given event layer, without knowing in advance which properties are set and available?
In that case, this is a simple JavaScript problem, for which you can use
Object.keys(feature.properties)
to get the array of available "attributes" infeature.properties
. Then simply iterate over that array:You could also use the for...in: