Access the Last Element
Fill in the Blank Easy
Question
Fill in the blank to get the last element of the array.
Code
const arr = [10, 20, 30];
const last = arr[___];
console.log(last); // 30
Hint
The last index is one less than the length.
Explanation
The last element is at index arr.length - 1. For an array of length 3, the last index is 2. So arr[arr.length - 1] gives arr[2] = 30. In modern JavaScript, you can also use arr.at(-1).
Related Resources
Related Lessons
- Arrays
Learn how arrays store ordered lists of values.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.