I create new array and add to her specific values. I add in first index and first index has value, but if I add in second or more index, last indexes are empty and I don't know why. Here my code.
const inputs = [...document.querySelectorAll('.input')];
let timeout = null;
inputs.forEach((input, index) => {
input.addEventListener('keyup', () => {
clearTimeout(timeout);
let inputValue = Number(input.value);
timeout = setTimeout(() => {
if (index !== 1) {
let arr = [];
if (index === 0) {
arr[0] = inputValue;
} else if (index === 2) {
arr[1] = inputValue;
} else if (index === 3) {
arr[2] = inputValue;
} else if (index === 4) {
arr[3] = inputValue;
}
console.log(arr);
}
}, 1000);
});
});
arrneeds to be a global variable.