i'm looping through an array of 3 buttons inside the for loop i have attached event Listener to each button i'm trying to console.log the button i'm currently looping through but it returns undefined.
let buttons = document.getElementsByClassName('btn');
for (i = 0; i < buttons.length; i++) {
buttons[i].addEventListener('click', function() {
console.log(buttons[i]);
// returns undefined
})
}
<button class='btn'>a</button>
<button class='btn'>b</button>
<button class='btn'>c</button>