Arrays and objects
The two core data structures — ordered lists and keyed records.
- Create and transform arrays with map and filter
- Create and access objects by key
- Destructure values out of arrays and objects
Almost all data in JavaScript is held in arrays (ordered lists) and objects (keyed records) — the data-structures fundamentals lesson in JS form. Together they model nearly anything.
Arrays
Ordered, zero-indexed, and full of useful methods:
const nums = [3, 1, 2];
nums[0]; // 3
nums.push(4); // [3, 1, 2, 4]
nums.length; // 4The transforming methods are the heart of idiomatic JS — each takes a function and returns a new array (no mutation):
[1, 2, 3].map((n) => n * 2); // [2, 4, 6]
[1, 2, 3, 4].filter((n) => n % 2); // [1, 3]
[1, 2, 3].reduce((a, n) => a + n); // 6Objects
An object maps string keys to values:
const user = { name: "Ada", born: 1815 };
user.name; // "Ada" (dot access)
user["born"]; // 1815 (bracket access)
user.role = "pioneer"; // add a key
Object.keys(user); // ["name", "born", "role"]Use an object when you look things up by name; an array when order and iteration matter — exactly the "let the operations choose the structure" rule.
Destructuring
A destructuring assignment is a clean way to pull values out by position (arrays) or name (objects):
const [first, second] = [10, 20]; // first = 10, second = 20
const { name, born } = user; // name = "Ada", born = 1815Destructuring shows up constantly in modern JS, especially in function parameters and imports.
Where to go next
Next: modules — splitting code across files with import and export.