I have an array that has the names of people. I want to use this array to cycle through every single person in the array and make a button with the name. That button will then get to console.log
the name of the person. The problem here is that I don't think I can use onClick in a template string lateral.
Here's something that it looks like.
let content = document.getElementById("content")
var array = ["John", "Adam", "Sid", "Edward"]
array.forEach(element => {
function runEvent() {
console.log(element)
}
content.innerHTML += `<button onclick="runEvent()">${element}</button>`
})
<div id="content">
</div>
How do I do this?