I am using a for loop to populate an HTML table with values from an array. Each row needs a button that links to a different URL.
thisbutton.addEventListener("click", function(){ window.location.href = finalurl; });
The string finalurl
changes each iteration of the loop. However it passes it as a reference, so as finalurl
changes in the next loops, the event listener is still tied to it. Meaning every button on the page is then linked to this same URL.
I need a way to pass a clone inside that function, all the ways of deep copying/cloning I have found so far would require me to set a separate variable which doesn't help because this would over write as well.