JavaScript Array Methods Cheatsheet 2026
Complete guide to JavaScript Array prototype methods, functional iteration, search techniques, transformations, and mutation styles.
Interactive Skill Mastery
Mark commands as learned to build your customized reference tracker. Retained locally in this browser.
Iterators
When to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
arr.forEach((item, index) => {
console.log(item, index);
});Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
const keys = arr.keys();
for (const key of keys) { ... }Output Example
// Returns transformed or queried elements depending on array dimensionsTransformers
When to Use
When you want to transform every single item in an array using a callback function, returning a brand new array of the same length.
Common Mistakes
Using map when you don't intend to return a value. If you are just running side-effects (like logging or updating DOM), use 'forEach' instead.
Shortcut / Pro-Tip
Can be chained directly: arr.map(...).filter(...)Example
const ages = [10, 20, 30];
const nextYearAges = ages.map(age => age + 1);Output Example
[11, 21, 31]When to Use
When transforming every element in an array, yielding a new array with the mapped outputs without mutating the original elements.
Common Mistakes
Using map for general loops without returning values. Use forEach instead.
Shortcut / Pro-Tip
Map preserves the exact length of the original array.Example
const arr = [1, 2, 3, 4, 5];
const nested = arr.flatMap(x => [x, x * 2]);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
const flatArr = nested.flat(2);Output Example
// Returns transformed or queried elements depending on array dimensionsFilters
When to Use
When you need to filter down elements from an array based on a boolean condition, yielding a clean subset array.
Common Mistakes
Expecting filter to mutate the original array. Filter is immutable and returns a *new* array.
Shortcut / Pro-Tip
Always returns an array, even if only 1 item matches, or an empty array [] if none match.Example
const prices = [15, 20, 35, 40];
const expensive = prices.filter(p => p > 30);Output Example
[35, 40]Searchers
When to Use
When searching for the existence, position, or specific value of items inside your array.
Common Mistakes
Forgetting that 'find' returns only the *first* matching element, or returns 'undefined' if no element matches.
Shortcut / Pro-Tip
Use 'some()' if you only need a quick true/false check on whether an element matches.Example
const arr = [1, 2, 3, 4, 5];
const found = arr.find(item => item.id === 42);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
When searching for the existence, position, or specific value of items inside your array.
Common Mistakes
Forgetting that 'find' returns only the *first* matching element, or returns 'undefined' if no element matches.
Shortcut / Pro-Tip
Use 'some()' if you only need a quick true/false check on whether an element matches.Example
const arr = [1, 2, 3, 4, 5];
const idx = arr.findIndex(item => item.id === 42);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
When searching for the existence, position, or specific value of items inside your array.
Common Mistakes
Forgetting that 'find' returns only the *first* matching element, or returns 'undefined' if no element matches.
Shortcut / Pro-Tip
Use 'some()' if you only need a quick true/false check on whether an element matches.Example
const arr = [1, 2, 3, 4, 5];
const contains = arr.includes(val);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
When searching for the existence, position, or specific value of items inside your array.
Common Mistakes
Forgetting that 'find' returns only the *first* matching element, or returns 'undefined' if no element matches.
Shortcut / Pro-Tip
Use 'some()' if you only need a quick true/false check on whether an element matches.Example
const arr = [1, 2, 3, 4, 5];
const firstIndex = arr.indexOf(val);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
const matchesAny = arr.some(x => x > 100);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
const matchesAll = arr.every(x => x > 0);Output Example
// Returns transformed or queried elements depending on array dimensionsReducers
When to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
const sum = arr.reduce((acc, curr) => acc + curr, 0);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
const sumRight = arr.reduceRight((acc, curr) => acc + curr, 0);Output Example
// Returns transformed or queried elements depending on array dimensionsMutators
When to Use
When directly mutating the array, removing, replacing, or appending items in memory.
Common Mistakes
Mutating array states directly in React. In React, always make a shallow copy (e.g. [...arr]) before modifying.
Shortcut / Pro-Tip
Splice mutates in-place, while slice creates a safe, immutable copy.Example
const arr = [1, 2, 3, 4, 5];
arr.push(newElement);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
When directly mutating the array, removing, replacing, or appending items in memory.
Common Mistakes
Mutating array states directly in React. In React, always make a shallow copy (e.g. [...arr]) before modifying.
Shortcut / Pro-Tip
Splice mutates in-place, while slice creates a safe, immutable copy.Example
const arr = [1, 2, 3, 4, 5];
const lastItem = arr.pop();Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
const firstItem = arr.shift();Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
arr.unshift(newFirstElement);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
const sliced = arr.slice(start, end);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
When directly mutating the array, removing, replacing, or appending items in memory.
Common Mistakes
Mutating array states directly in React. In React, always make a shallow copy (e.g. [...arr]) before modifying.
Shortcut / Pro-Tip
Splice mutates in-place, while slice creates a safe, immutable copy.Example
const arr = [1, 2, 3, 4, 5];
const removed = arr.splice(startIndex, count, item1);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
arr.sort((a, b) => a - b);Output Example
// Returns transformed or queried elements depending on array dimensionsWhen to Use
Use when you want to execute operations on JavaScript Arrays to transform, search, or mutate elements.
Common Mistakes
Mutating arrays accidentally when you should treat them immutably, especially in React states.
Shortcut / Pro-Tip
Chaining array methods together creates clean functional pipelines.Example
const arr = [1, 2, 3, 4, 5];
arr.reverse();Output Example
// Returns transformed or queried elements depending on array dimensionsJS Array Methods Best Practices
1Maintain Immutability
Avoid methods that mutate the original array (e.g. splice, push, sort) inside state-management libraries like React. Use map, filter, or slice instead.
2Return Values in Map/Reduce
Ensure your callback functions always return a value, otherwise map arrays will be populated with undefined.
3Use flatMap Over map.flat
Combining map and flat into flatMap() is cleaner, more performant, and executes in a single pass.
4Select the Right Search Tool
Use find() for objects, indexOf() for primitive values, and includes() for a quick boolean check.
5Provide Initial Value in Reduce
Always provide an initial accumulator value to prevent runtime type crashes on empty arrays.
Common JS Array Methods Errors & Solutions
Cannot read properties of undefined (reading 'map')
Ensure the variable is initialized as an array [] before running iteration loops. Guard it with optional chaining: arr?.map().
Array mutated directly inside React State
Do not use mutate methods. Create a shallow copy first (e.g. const newArr = [...oldArr]; newArr.push(x);) then update state.
reduce of empty array with no initial value
Always supply a fallback initial value as the second argument to reduce (e.g. arr.reduce((acc, x) => acc + x, 0)).
find() returns undefined
Always check if your search return matches undefined before reading properties on the output object.
sort() sorts numbers incorrectly
By default, sort() converts elements to strings. Pass a comparator function: arr.sort((a,b) => a - b) to sort numbers numerically.
Common JS Array Methods Interview Questions
Q1What is the difference between map() and forEach()?
map() transforms every element in an array and returns a brand-new array of identical length. forEach() executes side-effects for each element and returns undefined.
Q2What is the difference between slice() and splice()?
slice() is immutable and returns a shallow copy of a portion of an array. splice() is mutable and modifies the original array in-place by adding, replacing, or deleting elements.
Q3How does the reduce() method work?
reduce() runs a reducer callback function on each element of the array, passing the accumulated result from the previous iteration, yielding a single aggregated value.
Q4What does flatMap() do?
flatMap() applies a transformation callback to each element, and then flattens the result by one level, executing map and flat in a single optimized pass.
Q5What is the difference between find() and filter()?
find() returns only the first single element that matches the testing condition, while filter() returns a new array containing all elements that match.
Related Resources
REST API Tester
Test API routes and endpoints directly in your browser with full request controls.
JSON Formatter & Validator
Beautify, validate, and minify JSON structures instantly.
Best Free Online Developer Tools
An expert review of must-have online utilities for developers.
Git Cheatsheet
Essential command reference for local and remote version control repositories.
Generated from LearnHubly Developer Cheatsheets
Access interactive sandbox tests, tools, and developer code bases at https://www.learnhubly.com