Can someone please tell me why the length of secondArrayis 5 instead of 10?
The result I am looking for is for all elements to be popped off so the secondArray has an empty. However, it seems that only half of them are being popped off, even though I have set the (condition) of the for loop to go through the entire array. Can someone point out why this is?
Please Note: I understand this is not the only/or ideal way to remove elements from an array. This is simply some practice I am doing with for loops and Array methods.
my result looks like this after executing the code:
secondArray = 1,2,3,4,5,6,7,8,9,10
secondArray = 1,2,3,4,5
var secondArray = [1,2,3,4,5,6,7,8,9,10];
document.write("secondArray = " + secondArray)
for(i = 0; i < secondArray.length; i++){
secondArray.pop();
}
document.write("<br/>"+ "secondArray = " + secondArray)
secondArray.lengthchanges because you keep popping off elementssecondArray, then just dosecondArray.length = 0;.