I need the same result as:
var array = [1, 2, 3, 5, 7];
var top = array.pop();
The problem is that pop
removes the element from the array. To fix that I added another line:
array.push(top);
But it is annoying me, I did it four or five times in this project till now. Is there a better way?