Get coordinated when working with multiple traces

I have made a scatterplot using Plotlyjs with 4 traces, so the data looks like this:


Now I want y coordinate when the user clicks on the chart, how should I approach this, I tried using for loop with “plotly_click”, but I am getting wrong values with it. Can you guys help me here

for (var i=0; i<data.points.length; i++){
selectedPoint = 'y axis value is= '+data.points[i].y;

This loop always gives me the value of the last trace and is not showing the value of any other trace.