How to get the last item of array without pop with JavaScript?

Sometimes, we want to get the last item of array without pop with JavaScript.

In this article, we’ll look at how to get the last item of array without pop with JavaScript.

How to get the last item of array without pop with JavaScript?

To get the last item of array without pop with JavaScript, we can use the array at method.

For instance, we write:

const array = [1, 2, 3, 5, 7];
const last = array.at(-1)
console.log(last)

We call array.at with -1 to return the last entry of array.

Therefore, last is 7.

Conclusion

To get the last item of array without pop with JavaScript, we can use the array at method.