How to Get the Last Item in an Array
The first method for getting the last item is the length property. You can pick the last item by doing the following:
Another succinct method is used. The slice() method returns a new array copying to it all the items from index start to the end:
Both of them will return undefined if the array is empty.
The pop() method is also used; however, keep in mind that it removes the last element of the array and returns that element: