I am using arcgis javascript api . I want to remove a recently added layer , i wrote like this

var a = map.layerIds;
var b = map.getLayer(a[2]);

But I am not able to remove any layer.

  • are you refreshing after removing the layer ? – radouxju Feb 9 '16 at 14:45

try this

for (var j = 0, k = map.layerIds.length; j < k; j++) {
    var currentLayer = map.getLayer(map.layerIds[j]);
    if (currentLayer.id == "yourLayerID") {

That code should work. I'm guessing you don't have the right index of your a variable. Here's a jsfiddle showing your code working (click the "remove" button to run your code and see the layer get removed):


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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