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].

Answer from Michael Jones on Stack Overflow
🌐
Built In
builtin.com › articles › javascript-get-last-element-of-array
How to Get the Last Element of an Array in JavaScript | Built In
Summary: JavaScript offers multiple ways to get the last element of an array, including length - 1, slice(-1), pop(), at(-1) and more. Some methods mutate the original array, while others preserve it, making method choice dependent on use case. more JavaScript offers multiple ways to get the last element of an array, including length - 1, slice(-1), pop(), at(-1) and more.
🌐
CoreUI
coreui.io › blog › how-to-get-the-last-element-in-an-array-in-javascript
How to get the last element in an array in JavaScript · CoreUI
January 25, 2024 - Whatever the reason, JavaScript provides several ways to pinpoint and retrieve the last item in an array. The length property of an array reveals the number of elements it contains. Since JavaScript arrays are zero-indexed—meaning, the index of the first element is 0—the index of the last element will always be one less than the length of the array.
🌐
Reddit
reddit.com › r/javascript › the easy way to access the last javascript array element
r/javascript on Reddit: The easy way to access the last JavaScript array element
September 20, 2023 - Quite inefficient since it requires making a new, one element array, and destructuring that temporary array, every time you access the last element ... You can't blueball us without the output to that!
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › findLast
Array.prototype.findLast() - JavaScript | MDN
The findLast() method of Array instances iterates the array in reverse order and returns the value of the first element that satisfies the provided testing function. If no elements satisfy the testing function, undefined is returned.
🌐
Flexiple
flexiple.com › javascript › get-last-array-element-javascript
How to Get Last Element in an Array in JavaScript? - Flexiple
This method changes the length of the array. let arry = [2, 4, 6, 8, 10, 12, 14, 16]; let lastElement = arry.pop(); console.log(lastElement); //Output: 16 · Let us now use all three methods on an array to get the last element and check which method is the fastest · let arry = [2, 4, 6, 8, 10, 12, 14, 16]; console.time('array length property'); let lastElement = arry[arry.length - 1]; console.log(lastElement); console.timeEnd('array length property'); console.time('array slice method'); let lastElement1 = arry.slice(-1); console.log(lastElement1); console.timeEnd('array slice method'); console.time('array pop method'); let lastElement2 = arry.pop(); console.log(lastElement2); console.timeEnd('array pop method'); //Output: //16 //array length property: 13.798ms //[ 16 ] //array slice method: 8.839ms //16 //array pop method: 0.138ms
Find elsewhere
🌐
YouTube
youtube.com › watch
JavaScript Get Last Element Of Array Without Removing It | HowToCodeSchool.com - YouTube
Our Website: HowToCodeSchool.comIn this video we will learn How to Get Last Element of Array in JavaScript without removing it from the array. Which happens ...
Published   November 27, 2021
🌐
BackEndTea
backendtea.com › how-to › javascript-last-element-of-array
Finding the last element of an array in javascript | BackEndTea
July 22, 2024 - With Array.at you can simply pass -1 to get the last element, or -2 to get the second to last element, and so on. Or if that item does not exist, for example with an empty array, or with an array with less than n elements, it returns undefined
🌐
The Valley of Code
thevalleyofcode.com › how-to-get-last-item-array-javascript
How to get last element of an array in JavaScript?
To get the last item without knowing beforehand how many items it contains, you can use the length property to determine it, and since the array count starts at 0, you can pick the last item by referencing the <array>.length - 1 item.
🌐
Codedamn
codedamn.com › news › javascript
How to get last element in array using JavaScript (with examples)?
October 6, 2022 - for(let i=0;i<animals.length;i++) { //code to be executed }Code language: JavaScript (javascript) ... animals.length and to get the last element of the array, we can use the length property.
🌐
Zipy
zipy.ai › blog › get-the-last-item-in-an-array-using-javascript
get the last item in an array using javascript
April 12, 2024 - This article dives into various methods to retrieve the last element of an array in JavaScript, catering to developers aiming to refine their coding skills with simple yet effective techniques. Arrays in JavaScript are used to store multiple values in a single variable, providing a way to group related data. They are dynamic, allowing for elements to be added or removed...
🌐
Scaler
scaler.com › home › topics › get the last element of an array using javascript
Get the Last Element of an Array Using JavaScript - Scaler Topics
April 3, 2024 - For accessing that element from an array, we need to pass the index value of that particular element in a square bracket. Since the indexing starts from 0 in javascript, we need to write (length-1) to get the last element from an array or list ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-get-the-last-item-in-an-array-in-javascript
How to Get the Last Item in an Array in JavaScript
January 17, 2022 - When you’re programming in JavaScript, you might need to get the last item in an array. In this tutorial, we’ll go over two different ways to do this. Use index positioning if you know the length of the array. ... Here we can see that the last item in this array is horse. To get the last item, we can access the last item based on its index: ... JavaScrip arrays are zero-indexed. This is why we can access the horse element with animals[2]. If you aren't sure on what zero-indexed means, we'll go over it later on in this tutorial.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
JavaScript arrays are zero-indexed: the first element of an array is at index 0, the second is at index 1, and so on — and the last element is at the value of the array's length property minus 1.
🌐
Flexiple
flexiple.com › javascript › javascript-get-last-element-array
JavaScript: How to Get the Last Element of an Array - Flexiple
The flexibility of JavaScript arrays allows them to hold any type of data — numbers, strings, objects, or even other arrays. The simplest way to retrieve the last element of an array is by using the array's length property.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › get-the-first-and-last-item-in-an-array-using-javascript
JavaScript - Get first and last Item of JS Array - GeeksforGeeks
July 11, 2025 - The Array.at() method in JavaScript allows to access elements of an array by their index. To get the first and last elements of an array using the at() method, pass the desired indices to the method. The first element has an index of 0.
🌐
CoreUI
coreui.io › answers › how-to-get-the-last-element-of-an-array-in-javascript
How to get the last element of an array in JavaScript · CoreUI
September 21, 2025 - From my extensive expertise, the most reliable and universally supported approach is using array index notation with array.length - 1 to access the final position. This method is dependable, works across all JavaScript versions, and clearly ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › pop
Array.prototype.pop() - JavaScript | MDN
The pop() method is a mutating method. It changes the length and the content of this. In case you want the value of this to be the same, but return a new array with the last element removed, you can use arr.slice(0, -1) instead.