Arrays
Lists & Array Methods
Arrays are ordered collections that store multiple values in one variable. JavaScript arrays come with powerful built-in methods for adding, removing, searching, sorting, and transforming data.
An array is like a movie playlist. Add to end (push), remove from end (pop), add to start (unshift), remove from start (shift). Transform every title (map), keep only certain genres (filter), calculate total runtime (reduce).
🔑 Key Concepts
Create, read, and modify using 0-based indexes. push, pop, shift, unshift for adding/removing.
The power trio: map transforms, filter keeps matches, reduce accumulates to one value.
find, findIndex, includes, indexOf, some, every, sort, reverse - find and order elements.
💻 Code Examples
⚠️ Common Mistakes
Arrays start at index 1
Arrays are 0-indexed! First element is index 0, last is array.length - 1.
map/filter change the original array
These are NON-DESTRUCTIVE - they return a NEW array. Original stays the same.
.sort() without comparator on numbers
[10, 9, 100].sort() gives [10, 100, 9] (wrong!). Always use .sort((a,b) => a-b) for numbers.
📋 Quick Reference
Live Code Playground
Edit the code and press ▶ Run to see output instantly.