How to get the last item of an array and delete it from the array in JavaScript?

arrays, javascript

Solution

You want to do exactly what the `pop` method does:

var arr = [1,2,3,4];
//...
var last = arr.pop(); // returns 4, and arr will contain now [1, 2, 3]

Problem

``` var arr = [1,2,3,4]; ``` I need to get the last one and then delete it from an array called `arr`: ``` var arr = [1,2,3] ```

Original source