Problem solved,
if (this.map.getLayer (layerID)) this.map.removeLayer (this.map.getLayer (layerID));
where layerID is the given layer.id when the layer is created, e.g., could be the same as lyr.name in your case.
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.