Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am struggling with geojson popups in leaflet.js I have nested arrays as properties for my features - an example would be counts of fish caught at a location (not my actual project data!)


I am trying to put a popup on each feature (onEachFeature) that states river and a count of each type caught.

I'm binding using a function like this

function onEachFeature(feature, layer) {
        if ( {
            var popupcontent;
            popupcontent = "<span style='font-weight:bold'>River: </span>"
            for (i=0;i<;i=i+1){
                var fishstring = "<br><span style='font-weight:bold'>"[i].type+": </span>"
                popupcontent = popupcontent+fishstring;

geojson = L.geoJson(inData, {
    onEachFeature: onEachFeature

The problem is that the onEachFeature is caught in an endless loop. If I remove the for loop from the function, everything works fine.

Any thoughts on this?

share|improve this question
What happens if you put a semi-colon after your popupcontent = "... lines? Does the debug console say anything? Canyou set up a jsfiddle of this so that we can edit it? – Alex Leith Oct 22 '13 at 22:19
Thanks for the fiddle request. Of course, the fiddle works fine, and I have long since moved past this issue! Marking my question answered so others might see the code. Cheers! – abenrob Mar 3 '14 at 21:16

It looks like you have a typo in your for loop. It should be:

for (i=0;i<;i++)

instead of:

for (i=0;i<;i=i+1)

Notice that the first is incrementing i by one not adding 1 to i.

share|improve this answer
i++ and i=i+1 and i+=1 all do the same thing. I come from a python background,so often default to the latter 2... – abenrob Jan 5 '13 at 17:43
up vote 0 down vote accepted

For whatever it is worth, when I revisited this, and build the fiddle ( it now works... (thanks @alexgleith for the nudge!)

Marking complete so others might see the code.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.