+ 2

Why? As far I know pop remove last element.

var arr =[1,2,3,4,5]; for( var i=0; i < arr.length ; i++){ console.log(arr.pop()); } // 543

8th May 2020, 2:11 PM
Md Iftakher Hossain
Md Iftakher Hossain - avatar
3 Antworten
0
So what do you think is happening here?it is working as it should be but I would like to know what you don't understand 🤔
8th May 2020, 2:20 PM
Abhay
Abhay - avatar
0
popping elements changes the length of the array and i < arr.length becomes false, before you get to 2.
8th May 2020, 2:20 PM
Bahhaⵣ
Bahhaⵣ - avatar