Just like the title says, in my react app, array.push is not ever pushing anything. Im not talking about state, im talking about vanilla JS arrays. Im sure im doing something really dumb.
In the code below i will send over an answer object to selectedAnswer().
The object looks like
{answer: “first answer”, correct: true}
or
{answer: “second answer”, correct: false}
…etc
var userAnswers = [];
function selectedAnswer(choice) {
userAnswers.push(choice)
}
I will ALWAYS receive back the userAnswers array as the last object i tried to push to the array. If i answer 4 times in a row, the last thing i pushed to the array is in the [0] index and nothing else is in the array
i have also tried this with no luck
function selectedAnswer(choice) {
var newArray = [...userAnswers, choice]
userAnswers= newArray;
}
What am i doing wrong here, what basic JS fundamental did i forget.