Learning overview
- Estimated time
- 4 minutes
- Difficulty
- Beginner
- Prerequisites
- No prior experience required
- Learning outcome
- Explain javascript using a clear mental model · Apply javascript in practical JavaScript work
- Last updated
- July 18, 2026
Use arrays for ordered collections
Arrays are objects specialized for indexed values and a length. Indexes begin at zero. Use them when order and iteration matter; use an object or Map when named lookup is the primary relationship.
Choose methods by result
Map returns one transformed item for each input, filter returns matching items, find returns the first match, some and every return booleans, and reduce combines a collection into another value.
const lessons = [
{ title: "Variables", minutes: 12, complete: true },
{ title: "Arrays", minutes: 18, complete: false },
];
const remaining = lessons.filter((lesson) => !lesson.complete);
const titles = remaining.map((lesson) => lesson.title);
const totalMinutes = lessons.reduce((sum, lesson) => sum + lesson.minutes, 0);Make updates explicit
Spread, slice, map, and filter create new arrays but only copy one level. Nested objects remain shared unless they are copied too. Sort mutates the array; use toSorted when supported or copy before sorting.
const updated = lessons.map((lesson) =>
lesson.title === "Arrays"
? { ...lesson, complete: true }
: lesson
);
const byDuration = lessons.toSorted((a, b) => a.minutes - b.minutes);Frequently asked questions
What is the difference between map and forEach?
Map returns a new array of transformed values. ForEach returns undefined and is appropriate for deliberate side effects.
Does spread make a deep copy of an array?
No. It creates a shallow array copy. Nested objects and arrays still refer to the same values unless copied separately.
Topic graph
A taxonomy-generated path through this subject.
Related courses
Related learning
Recommended automatically from shared technologies, topics, intent, and difficulty.
Related Guides
Related Tutorials
Related Glossary
Related Cheatsheets
Related Projects
Related Interview Questions
Related reading
Hand-picked companion pages that deepen this topic.
Your next steps
