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?
When grabbing from the end you can do array[array.length - x], where x is the number of items from the end you wanna grab.
For instance, to grab the last item you would use array[array.length - 1].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With