Im trying to collect user input into array but everytime i do the previous is being replaced.Here is my code
let inputValue = input.value;
let inputArray = [];
inputArray.push(inputValue);
console.log(inputArray);
Im trying to collect user input into array but everytime i do the previous is being replaced.Here is my code
let inputValue = input.value;
let inputArray = [];
inputArray.push(inputValue);
console.log(inputArray);
Your declaring your inputArray as empty all the time, if you have that code inside a function scope like this:
function collectUserInput() {
let inputValue = input.value;
let inputArray = [];
inputArray.push(inputValue);
console.log(inputArray);
}
you need to declare the inputArray outside the function so evertyme you call the ollectUserInput you add one more input to the pre-existing array, like this:
let inputArray = [];
function collectUserInput() {
let inputValue = input.value;
inputArray.push(inputValue);
console.log(inputArray);
}