JS-051

Beginner5 min~5 min read#array#arrays#collection
Array
Store multiple values
Goal
Learn to use arrays to store multiple values in a single variable.
Explanation
- An Array is an ordered list of values.
- An array can hold many elements.
- Elements are written inside square brackets [].
- Each element has its own number called an index.
- Arrays are used in almost every program.
Analogy
Imagine a box containing several fruits. Instead of using a separate box for each fruit, you store them all in one container.
Code
const fruits = [
"Apple",
"Banana",
"Orange"
];
console.log(fruits[0]);Result: Apple
Common mistake
Beginners often think the first index is 1. In fact, array indexes start at 0.
Remember
- ✦ An Array stores multiple values.
- ✦ An array is created using [].
- ✦ Elements have indexes.
Quick Quiz
What does fruits[0] return for ["Apple", "Banana", "Orange"]?