Sitemap

πŸ“¦ JavaScript Array -

2 min readSep 26, 2026

--

Imagine Riya has a big fruit box 🍎🍌🍊.

Instead of keeping every fruit in a separate box, she puts all the fruits into one big box. This big box is like a JavaScript Array.

πŸ“– Story

Riya creates a fruit box:

let fruits = ["Apple", "Banana", "Mango", "Orange"];

Her box looks like this:

πŸ“ FRUIT BOX
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Apple β”‚ Banana β”‚ Mango β”‚ Orange β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
0 1 2 3
Index Index Index Index

πŸ‘‰ Each item has a position called an index.

Get Raveenanagar’s stories inΒ yourΒ inbox

Join Medium for free to get updates fromΒ thisΒ writer.

Important: JavaScript arrays start counting from 0, not 1.

πŸ” Getting a Fruit

Riya wants the Mango:

console.log(fruits[2]);

Output:

Mango

Because Mango is at index 2.

βž• Adding a Fruit

Riya buys Grapes and puts them in the box:

fruits.push("Grapes");

Now:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Apple β”‚ Banana β”‚ Mango β”‚ Orange β”‚ Grapes β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
0 1 2 3 4

πŸ—‘οΈ Removing a Fruit

She removes the last fruit:

fruits.pop();

Grapes are removed from the end.

🧠 Simple Definition

An array is a container that stores multiple values in a single variable.

let fruits = ["Apple", "Banana", "Mango"];

Think of it as:

Array = 🧺 One basket β†’ πŸ₯­ Many items

🌟 Easy Formula

ARRAY
↓
One container
↓
Multiple values
↓
Each value has an index
↓
Index starts from 0
Press enter or click to view image in full size

--

--