A Beginner's Guide to JavaScript Arrays Explained with a Shelf Analogy


An array is like a shelf that lets you store multiple items in one place.
Instead of creating separate variables for each value, you group them together.
Think of it as a list of things — organized and easy to access.
🔹 Example
let fruits = ["apple", "banana", "cherry"];
This is an array with 3 items:
apple, banana, cherry
📌 What You Can Do with Arrays
✅ 1. Access Items by Index
console.log(fruits[0]); // apple
console.log(fruits[1]); // banana
🔧 Method used: Bracket notation []
🧠 Index starts from 0
✅ 2. Change an Item
fruits[1] = "mango";
console.log(fruits); // ["apple", "mango", "cherry"]
🔧 Method used: Bracket notation with assignment fruits[index] = value
✅ 3. Add an Item
fruits.push("orange");
console.log(fruits); // ["apple", "mango", "cherry", "orange"]
🔧 Method used: .push()
✅ 4. Remove the Last Item
fruits.pop();
console.log(fruits); // ["apple", "mango", "cherry"]
🔧 Method used: .pop()
✅ 5. Check Array Length
console.log(fruits.length); // 3
🔧 Method used: .length
📏 Returns the number of items in the array.
🌿 Little Reminder
Arrays are foundational in JavaScript —
From storing names to handling complex data, they’re everywhere ✨
Master the basics, and you’ll unlock so many possibilities 💡
Written by Akum Imchen |Mentored and guided by Devsync
Subscribe to my newsletter
Read articles from Akum Imchen directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
