bmgustafson

Iterating over the Layers in a service

Discussion created by bmgustafson on Sep 9, 2011
Latest reply on Sep 20, 2011 by sli-esristaff
I want to do a foreach loop over the layers in a service then test to see if the name matches the name that I passed in.  I am doing this to get the layer ids for the identify task.  I used a similar function in silverlight but I cannot convert it to java script.  Any ideas?

function GetLayerId(LayerName)
        {
            var i = -1;
            var lyr = new esri.layers.ArcGISDynamicMapServiceLayer("...")

            lyr.layerInfos.forEach(
                function x(value) {
                    alert(value);
                    if (value.name.toUpper() == LayerName.toUpper()) {
                        i = value.id;
                    }
                }
            );

            return i;
        }

Outcomes