Link Popup Modal to correct script in loop
This is just a JavaScript problem. You have to add an event listener to the marker which opens the corresponding popup.

I put together a little example on JSBin here: https://jsbin.com/tigefikalu/edit?html,js,console,output

Hope that helps with the logic.