Array Methods in JavaScript You Must Know
Reviewed & published by Brayan K
A comprehensive guide to JavaScript array methods like map, filter, and reduce, with practical examples.
Arrays are the backbone of JavaScript. Whether you're building apps, games, dashboards, APIs, or full SaaS platforms, 80% of real-world JS coding involves arrays.
But many beginners only use for loops and .push() — missing out on powerful methods that simplify code, boost performance, and make you think like a professional JavaScript developer.
This guide covers every essential array method you must know, with simple explanations and real-use examples.
1. map() — Transform Each Item
map() creates a new array by applying a function to each element.
Use when you need:
- Format data from an API
- Produce transformed lists
- Build UI lists from data
map() is the MOST used array method in modern JS.
2. filter() — Keep Only What You Need
filter() returns a new array containing only the elements that pass a condition.
- Filtering products
- Filtering active/completed tasks
3. reduce() — Combine Everything Into One Value
reduce() is powerful. It converts an array into a single value (number, object, string, etc.).
- Analytics (views, likes, revenue)
- Counting occurrences
- Merging arrays into objects
4. forEach() — Loop Without Returning Anything
Used to run a function for each element.
Use when you don't need a returned array.
5. find() — Get the FIRST Match
Finds the first item that matches a condition.
- Finding user by ID
- Selecting product by SKU
- Locating settings in arrays
6. findIndex() — Get the Index of the First Match
Useful when updating or deleting items inside an array.
7. some() — Does AT LEAST ONE Match?
- At least 1 item selected
- Check if user has permissions
- Check if a value exists
8. every() — Do ALL Items Match?
- Form validation
- Checking all tasks completed
- Ensuring all values meet criteria
9. includes() — Quick Existence Check
Faster and cleaner than manual loops.
10. sort() — Sort Arrays (but be careful!)
Sorts in place, meaning it modifies original array.
Always use a compare function for numbers; otherwise results are wrong.
11. slice() — Copy or Extract Portions
Great for pagination or copying arrays.
12. splice() — Remove / Replace Items (Mutates!)
Use carefully—it edits the original array.
13. flat() — Flatten Arrays
Helpful with nested API responses.
15. join() — Convert Array to String
Essential for CSV, logs, and UI formatting.
When to Use Which Method? (Quick Guide)
| Goal | Best Method |
|---|---|
| Transform array | map |
| Keep only some items | filter |
| Combine all items | reduce |
| Loop only | forEach |
| Find 1 item | find |
| Check if exists | some / includes |
| Validate all items | every |
| Sort | sort |
| Create copy | slice |
| Modify original | splice |
Conclusion
Mastering these array methods will instantly:
- ✔ Make your code cleaner
- ✔ Reduce your bugs
- ✔ Help you write real-world apps
- ✔ Prepare you for interviews
- ✔ Level-up your JS problem-solving
These are the exact tools used by:
- Every serious JS developer
Related articles
- Async/Await in JavaScript Explained — Master asynchronous JavaScript with async/await and handle promises like a pro.
- Understanding the DOM in JavaScript — Master DOM manipulation in JavaScript. Learn element selection, event handling, content modification, performance optimization, and build dynamic interactive websites.
- Understanding JavaScript Closures — Master one of JavaScript's most powerful and misunderstood features with practical examples.