I'm using the ArcGIS API for JavaScript v. 3.x and I want to us the map.addLayer(layer, index) function, however, the documentation is fairly weak. From my experience, I believe it is the index from bottom to top of the layer in all operational layers. However, I don't see a good function to retrieve the index of a layer. Since I am programmatically inserting layers into the map and since I have a large number of layers, I need to be able to look up a layer by its ID and get its index. Is there anything OOTB for this? Also, is the index for all operational layers or just within map.layerIds or map.graphicsLayerIds? I notice it's easier to handle in the 4.x API, so I am guessing this is a weakness in the API or my knowledge.
https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#addlayer
addLayer(layer, index?)