JavaScript Array Methods 2026 — Complete Guide With Real Examples
Arrays are how JavaScript stores lists of data — a list of products, a list of users, a list of search results. And array methods are the tools that let you work with that data elegantly. Knowing these methods well is what separates developers who write ten lines of clean code from those who write fifty lines of messy loops. This guide covers every important array method with real, practical examples you can use immediately.
Every example in this guide runs in your browser console right now. Press F12 → click Console → paste any code → press Enter. Or test it in our free HTML Editor Online Pro inside a <script> tag.
What is a JavaScript Array — and Why Do Methods Matter?
An array is an ordered list of values stored in a single variable. Think of it as a numbered container — you can put strings, numbers, objects, or even other arrays inside it, and access each item by its position (called an index, starting at 0).
Array methods are built-in functions that let you manipulate, transform, and query arrays without writing manual loops every time. They make your code shorter, more readable, and much easier to reason about. In 2026, these methods — especially map, filter, and reduce — are considered fundamental JavaScript knowledge that every developer must know.
Mutating vs Non-Mutating: Some array methods change (mutate) the original array. Others return a new array and leave the original untouched. Knowing which is which prevents many subtle bugs. We'll mark each method clearly throughout this guide.
forEach — Loop Through Every Item
forEach is the simplest array method. It calls a function once for every item in the array. That's it. It doesn't return anything — it's purely for side effects like logging, updating the DOM, or triggering actions. Think of it as a clean replacement for a for loop.
map — Transform Every Item Into Something New
map is one of the most used array methods in all of JavaScript. It takes every item in an array, transforms it with a function, and returns a brand new array of the same length with the transformed values. The original array is never touched.
The mental model that makes map click: imagine a factory assembly line. Items go in one end, get transformed at each station, and come out the other end as something new. The input array and the output array always have the same number of items.
map vs forEach: Use map when you want to create a new array of transformed values. Use forEach when you want to do something with each item but don't need the result as a new array. If you find yourself building an array manually inside a forEach, switch to map.
filter — Keep Only the Items You Want
filter creates a new array containing only the items that pass a test you define. For each item, your function returns true (keep it) or false (skip it). The resulting array can be shorter than the original — or even empty if nothing passes the test.
reduce — Boil an Array Down to a Single Value
reduce is the most powerful and most misunderstood array method. It processes each item in the array and accumulates a single result — a sum, an object, a string, another array. Once you truly understand reduce, you realize you can use it to build almost anything.
The function you pass to reduce receives two key arguments: the accumulator (the running result so far) and the current item (the element being processed). Whatever you return from the function becomes the new accumulator for the next iteration.
Always provide an initial value as the second argument to reduce. Without it, reduce uses the first array item as the initial accumulator — which works for numbers but causes silent bugs with objects and strings. Make it a habit: always pass the initial value.
find, findIndex, some, every — Searching Arrays
Sometimes you don't want to transform or filter an array — you just want to find something in it, or check if something exists. These four methods handle exactly that, each returning a different type of result.
sort and reverse — Ordering Arrays
sort reorders the items in an array. reverse flips the order. Both of these methods are important — and both have a gotcha that catches almost every beginner at least once.
sort() mutates the original array. If you want to sort without changing the original, make a copy first: const sorted = [...originalArray].sort(...). The spread operator [...arr] creates a shallow copy, so sort operates on the copy instead of the original.
push, pop, shift, unshift, splice — Modifying Arrays
These are the classic methods for adding and removing items from arrays. They all mutate the original array — which is sometimes exactly what you want.
slice, concat, flat, includes — Essential Utilities
These four methods handle slicing arrays, combining them, flattening nested arrays, and checking if a value exists. You'll reach for all of them regularly in real projects.
Complete Array Methods Cheatsheet — Quick Reference
Bookmark this table. Every important JavaScript array method in one place.
| Method | Returns | Mutates? | One-line description |
|---|---|---|---|
forEach(fn) | undefined | No | Run a function on each item |
map(fn) | new array | No | Transform each item → new array same length |
filter(fn) | new array | No | Keep only items where fn returns true |
reduce(fn, init) | any value | No | Accumulate items into a single result |
find(fn) | item or undefined | No | First item where fn returns true |
findIndex(fn) | number (-1) | No | Index of first match, or -1 |
some(fn) | boolean | No | True if at least one item passes |
every(fn) | boolean | No | True only if ALL items pass |
includes(val) | boolean | No | True if val exists in array |
indexOf(val) | number (-1) | No | Index of first occurrence of val |
sort(fn) | same array | ⚠️ YES | Sort items in place |
reverse() | same array | ⚠️ YES | Reverse order in place |
push(...items) | new length | ⚠️ YES | Add items to end |
pop() | removed item | ⚠️ YES | Remove last item |
shift() | removed item | ⚠️ YES | Remove first item |
unshift(...items) | new length | ⚠️ YES | Add items to beginning |
splice(i,d,...add) | removed items | ⚠️ YES | Add/remove/replace at any position |
slice(start,end) | new array | No | Copy a portion of the array |
concat(...arrays) | new array | No | Merge arrays together |
flat(depth) | new array | No | Flatten nested arrays |
flatMap(fn) | new array | No | map() then flat(1) |
join(separator) | string | No | Convert array to a string |
Array.from() | new array | No | Create array from any iterable |
Array.isArray() | boolean | No | Check if something is an array |
Practice Array Methods in Your Browser — Free
Open HTML Editor Online Pro, write a script tag with your array code, and run it instantly. Experiment freely — change the data, chain methods together, break things and fix them. That's how JavaScript actually gets learned.
⚡ Open Free HTML Editor →Frequently Asked Questions About JavaScript Array Methods
Q: What is the difference between map and forEach?
Both iterate through every item in an array. The difference is what they return. map returns a new array of the same length with the transformed values — use it when you want a new array. forEach returns nothing (undefined) — use it when you want to perform an action on each item but don't need the result as a new array. If you're building a new array inside a forEach, that's usually a sign you should be using map.
Q: When should I use filter vs find?
Use filter when you want all items that match a condition — it always returns an array (which may be empty). Use find when you want just the first match — it returns the item itself (or undefined). If you're looking up a specific record by ID, find is the right choice. If you're filtering a list to show active items, filter is right.
Q: Is reduce hard to understand?
It takes a bit more time to understand than map and filter, but once it clicks, it becomes one of your most-used tools. The mental model: imagine reduce walking through the array item by item, carrying a "running total" (the accumulator). At each step, it updates the total based on the current item. When it reaches the end, it returns the final total. That "total" can be a number, string, object, or another array.
Q: Why does sort() behave strangely with numbers?
By default, sort() converts items to strings and sorts them lexicographically (like a dictionary). That means 10 comes before 2 because "1" comes before "2" alphabetically. Always pass a comparison function when sorting numbers: array.sort((a, b) => a - b). The function returns negative if a should come first, positive if b should come first, and 0 if equal.
Q: Can I chain array methods together?
Yes — and this is one of the most powerful patterns in JavaScript. Since methods like map and filter return new arrays, you can chain them: users.filter(u => u.active).map(u => u.name).sort(). Just be mindful of performance with very large arrays — each chained method creates a new array and iterates through it. For very large datasets, a single reduce may be more efficient than multiple chained methods.