Assuming you are using checkboxes to toggle on/off your layers, you can monitor where the checkbox's value is true. Then in the returned results of an identify if your layer has been toggled on and you actually have a result for that layer, values will be written out. I've used this approach with tabbed infowindows. You might be clicking on a location on the map that you don't have any data but the layer has been set to be visible. Your results for that layer will be 0 but the tab would still show up in your tabbed infowindow. Using the approach I just described will make sure you won't get that tab if there are no results.