I have a map service located here: River/GDT_SDE (MapServer) that has 10 sub layers. I want to use queryFeatures on the "Waypoints" sublayer. How can I loop through all of the layers in the map (sublayers too) and find that layer by its name and then call queryFeatures on it? In the examples I have seen, a new FeatureLayer is always created... I don't want to create a new FeatureLayer from the URL, but rather get it from the map.
(queryFeatures is documented here: FeatureLayer (legacy) | API Reference | ArcGIS API for JavaScript ).