I have an array of questions for an interactive quiz game. When you answer a question, functionally I want that question to be removed from the array (cat4Questions) so that it won’t come back for the player so I tried to splice it.
I wasn’t sure if it was working so I traced the array. While I was expecting “question1, question2, question3, question4” to be traced, “question1, question2, question3, question4, question5” was the result of my trace.
This is the line of code where I try to splice the array:
cat4Questions.splice(cat4Questions.length,1);
trace(cat4Questions);
You should take a look at
shift()andpop()array methods.shift()Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1.
pop()Removes the last element from an array and returns the value of that element.
In your case, you probably need the pop() function to remove the last element of the array.