The ArcGISDynamicMapServiceLayer.setVisibleLayers(ids, doNotRefresh?) method only takes an array of layer IDs. But, you can use a 2D array to hold the layer name and id information, which can be used later to get the layer's id from this 2D array based on the layer's name.For example:var items = [["One", 0],["Two", 1],["Three", 2]]; //format: [name,id] Note: check service REST endpoint to get the information about layer name and id
var visible =[];
var lyrName = "Three"; //layer wants to be turned on
for (var i = 0; i < items.length; i++){
if (items[0] == lyrName) {
visible.push(items[1]);
break;
}
}
agsDynamicMapServiceLayer.setVisibleLayers(visible);