How to highlight a clicked Feature Layer using ArcGIS JS API 4.x

This was answered on the Esri forums at https://geonet.esri.com/message/609517#comment-609517

view.on("click", function(event) {  
  view.hitTest(event.screenPoint).then(function(response) {  
    var graphics = response.results;  
    graphics.forEach(function(graphic) {  
      console.log(graphic);  
    });  
  });  
}); 

The benefit here over how you would have done it in 3.x is that in 3.x you would only get the top-most graphic that was clicked. Now you'll get any graphics under the location where you clicked by using the hitTest.


The code mentioned by Stephen can be used to get the coordinates of the clicked feature, then we can use graphic class(example: https://developers.arcgis.com/javascript/latest/sample-code/get-started-graphics/index.html) to draw and highlight the feature.