+ 1
What is function pop() doing here?
var arr = [45, 76, 34, 23, 85]; for(var i = 0; i < arr.length; i++) { console.log(arr.pop()); }//output:85,23,34
2 Respostas
+ 3
It removes the last element in the array. But in the same time the length of the array is decreased.
+ 2
The pop() method removes the last element from an array and returns that element.
This method changes the length of the array.
e.g.
var arr = [45, 76, 34, 23, 85];
console.log(arr.pop());
//expected output '85', length of arr decreased from 5 to 4;