I want to store my input values into an array.
When i click enter i get the input value and push into vals array.
Then i console log but whenever i click enter, it only push last input value.
Why?
var input = document.getElementById("input");
input.addEventListener("keyup", function(e) {
var val = e.target.value;
var vals = [];
if (e.which == 13) {
vals.push(val);
input.value = " ";
console.log(vals);
}
}, false);
valseverytime thekeyuplistener is executed. Move it out of that listener.