The monitored value of the input during the focus on it?

There are n-nnoe number of input. They are all one class. Every time you load the page, their number varies from 10 to 50. Need to track the focus and values of inputa on which to focus. The example below does not work
<input class="myinput">
<input class="myinput">
<input class="myinput">
<input class="myinput">
<input class="myinput">
<input class="myinput">
<input class="myinput">

var elem = document.getElementsByClassName('myinput');
 for (var i = 0; i < elem.length; i++) {
 elem[i].id='phonemid' +i;
};
 setInterval(function() {
 for (var i = 0; i < elem.length; i++) {
 var last = document.getElementById("phonemid" +i);
 last.onfocus = function() {
 var my = elem[i];
console.log(my.value);};
};
 }, 300);
June 7th 19 at 14:27
3 answers
June 7th 19 at 14:29
June 7th 19 at 14:31
June 7th 19 at 14:33
var elem = document.getElementsByClassName('myinput');

for (let i = 0; i < elem.length; i++) {
 elem[i].addEventListener('input', function() {
 console.log(this.value, 'this index' + i);
})
}

Here is the solution that solves the issue 100%. Colleagues from stackoverflow suggested.

Find more questions by tags JavaScriptjQuery