How to get the second to last item of an array with JavaScript? To get the second to last item of an array with JavaScript, we use the length subtract by 2 index. For instance, we write const pgUrl = array[array.length - 2]; to get the 2nd last item in array with index array.length - 2.