JavaScript Arrays

Master array creation, manipulation, and advanced operations

1
2
3
Array Basics & Creation

📚 What Are Arrays?

Arrays are list-like objects that store multiple values in a single variable. They're perfect for managing collections of related data like shopping lists, user names, or scores.

const shopping = ["bread", "milk", "cheese"]

🏗️ Array Creation Syntax

Square Brackets [ ]
const fruits = ["apple", "banana", "orange"]
Mixed Data Types
const mixed = [42, "hello", true, [1, 2]]
Array Length
fruits.length // returns 3

🔢 Zero-Based Indexing

Arrays start counting from 0, not 1!

Index 0
"bread"
Index 1
"milk"
Index 2
"cheese"
Index 3
"hummus"
Interactive Shopping List

Current Array:

Length: 5
0"bread"
1"milk"
2"cheese"
3"hummus"
4"noodles"
Array representation: ["bread", "milk", "cheese", "hummus", "noodles"]
🔍 Find Items
🔄 Array Transformations
Numbers Array:
Original: [5, 2, 7, 6]
Cities Filter:
All cities: ["London", "Liverpool", "Totnes", "Edinburgh", "Manchester"]
🔗 String ↔ Array
split(",") result:
[]
array.join(",") result:
""
Pro Tips
💡Arrays are zero-indexed: first item is at index 0, not 1
🎯Use push() to add, pop() to remove from end
map() transforms, filter() selects items
🔄Use split() and join() to convert strings ↔ arrays