← Back to Home

🥚 Arrays: Think Egg Cartons

Egg carton with numbered slots

Arrays are ordered collections that store multiple values in a single variable. Think of them as egg cartons - organized containers with numbered slots.

🥚 The Egg Carton Analogy

An egg carton has numbered slots (0, 1, 2, 3...) and each slot can hold one egg. Arrays work the same way - they have numbered positions (called indexes) and each position holds one value.

Why Arrays Matter

Without arrays, storing multiple related items would be messy:

With arrays:

Array Basics

Index Numbers: Arrays start counting at 0

fruits = ["Apple", "Banana", "Orange"]

Index 0: Apple
Index 1: Banana
Index 2: Orange

Common Array Operations

Real-World Examples

Accessing Array Items

Example: Todo List

todos = ["Buy milk", "Call mom", "Finish project"]

First task: todos[0] = "Buy milk"
Last task: todos[2] = "Finish project"

Arrays vs Single Variables

Single Variable: One box, one item

Array: One carton, many items organized by position

The bottom line: Arrays are essential for storing collections of related data. Just like an egg carton keeps eggs organized and easy to access, arrays keep your data organized with numbered positions. Master arrays, and you can handle lists of any size!

Arrays Data Structures Lists