JS-052

Beginner4 min~4 min read#array#index#arrays
Array Index
An element's position
Goal
Learn to find array elements by their index.
Explanation
- Every element in an array has its own number.
- This number is called an index.
- The first element always has index 0.
- The second element has index 1.
- You can use an index to access any element in an array.
Analogy
Imagine shelves in a cabinet. Each shelf has a number, so you can easily find the item you need.
Code
const fruits = [
"Apple",
"Banana",
"Orange"
];
console.log(fruits[0]);Result: Apple
Common mistake
Beginners often think the first element has index 1. In JavaScript, indexing starts at 0.
Remember
- ✦ An index is an element's number.
- ✦ The first index is always 0.
- ✦ Elements are accessed using square brackets [].
Quick Quiz
What is the index of the first element in an array?