Javascript Array Methods: Full Guide With Clear Examples

Javascript arrays come with a large amount of built-in methods. It’s impossible (and unnecessary) to memorize all of them. A better approach is to learn about them gradually: understand what each method does, when it’s useful and try it out in real code.

Over time, as you experiment and build real projects, you’ll naturally start remembering the ones you use most and your code will be cleaner, safer and even easier to maintain.

This guide organizes almost every array method with clear examples into easy-to-read tables. Consider it your roadmap for learning arrays step by step.

If you’re just starting out, this quick intro is a great place to begin: 6 Must-Know JavaScript Array Methods (With Simple Examples)

1. Transform Methods

FunctionMutates?What It DoesExampleOutputNotes
map()NoTransform each item; returns the same-length new array.[1,2,3].map(n => n * 2)[2,4,6]Use for one-to-one transformations; avoid side-effects (forEach instead).
flatMap()Nomap() followed by one-level flattening.[1,2].flatMap(n => [n, n * 2])[1,2,2,4]Useful for mapping + expanding values.
flat()NoFlattens nested arrays by a given depth.[1,[2,[3]]].flat(2)[1,2,3]Deep flattening can be expensive.

2. Filtering & Searching

FunctionMutates?What It DoesExampleOutputNotes
filter()NoReturns items matching a condition.[1,2,3,4].filter(n => n % 2 === 0)[2,4]Creates a new, shorter array.
find()NoReturns the first matching item.[3,6,9].find(n => n > 4)6Stops as soon as it finds a match.
findIndex()NoReturns index of the first match.[3,6,9].findIndex(n => n > 4)1-
findLast()NoReturns the last matching item.[1,2,3,4].findLast(n => n < 4)3Searches from the end.
findLastIndex()NoIndex of the last match.[1,2,3,4].findLastIndex(n => n < 4)2-
includes()NoChecks if a value exists.['a','b'].includes('a')trueMore readable than indexOf().

3. Reducing & Aggregation

FunctionMutates?What It DoesExampleOutputNotes
reduce()NoCombine items left → right into one output.[1,2,3].reduce((a,n) => a + n, 0)6Works for sums, grouping, flattening, etc.
reduceRight()NoLike reduce() but right → left.['a','b','c'].reduceRight((a,c) => a + c)'cba'Useful for right-associative operations.

4. Condition Checking

FunctionMutates?What It DoesExampleOutputNotes
some()NoReturns true if any value matches.[1,3,5].some(n => n % 2 === 0)falseStops early for efficiency.
every()NoTrue only if all values match.[2,4,6].every(n => n % 2 === 0)trueUseful for validation checks.

5. Sorting & Reordering

FunctionMutates?What It DoesExampleOutputNotes
sort()YesSort array in place.[3,1,2].sort()[1,2,3]Mutates — be careful with shared state.
reverse()YesReverse array in place.[1,2,3].reverse()[3,2,1]Mutates.
toSorted()NoReturns a sorted copy.[3,1,2].toSorted()[1,2,3]Safe alternative to sort().
toReversed()NoReturns a reversed copy.[1,2,3].toReversed()[3,2,1]Safe alternative to reverse().

6. Adding & Removing Items (Mutating)

FunctionMutates?What It DoesExampleOutputNotes
push()YesAdd item(s) to the end.arr.push(4)4Returns new length.
pop()YesRemove item from the end.arr.pop()4Returns removed item.
shift()YesRemove first item.arr.shift()1Slower than pop().
unshift()YesAdd item(s) to the start.arr.unshift(0)4Returns new length.
splice()YesAdd/remove at any index.arr.splice(1,1)[2]Extremely flexible but mutates.

7. Non-Mutating Alternatives

FunctionMutates?What It DoesExampleOutputNotes
slice()NoExtract a portion.[1,2,3].slice(1)[2,3]Commonly used to copy arrays.
concat()NoMerge arrays.[1].concat([2,3])[1,2,3]Can replace push() for immutable code.
toSpliced()NoNon-mutating version of splice().[1,2,3].toSpliced(1,1)[1,3]Ideal for React/immutable patterns.

8. Combining & Converting

FunctionMutates?What It DoesExampleOutputNotes
join()NoTurn array into string.['a','b'].join('-')'a-b'Good for CSV, lists, paths.
Array.from()NoConvert iterable → array.Array.from('hi')['h','i']Works with NodeLists, Sets, etc.
Array.of()NoCreate an array from arguments.Array.of(1,2)[1,2]Avoids quirks of new Array().
Array.isArray()NoCheck if value is an array.Array.isArray([])true-
indexOf()NoFirst index of a value.['a','b','a'].indexOf('a')0Use includes() when checking existence.
lastIndexOf()NoLast index of a value.['a','b','a'].lastIndexOf('a')2-
at()NoAccess by index (supports negatives).[1,2,3].at(-1)3Cleaner than arr[arr.length - 1].

Final Summary

A compact overview with recommended use-cases.

CategoryMethodsRecommended Use
Transformmap, flat, flatMap, reduce, reduceRightConverting data, mapping, flattening, building new results.
Filter/Searchfilter, find, findIndex, findLast, findLastIndex, some, every, includesExtracting items, locating values, validation checks.
Reordersort, reverse, toSorted, toReversedSorting or reversing data; prefer non-mutating versions.
Add/Removepush, pop, shift, unshift, splice, slice, toSpliced, concatManaging list changes; choose non-mutating alternatives.
Utilityflat, join, Array.from, Array.of, Array.isArray, indexOf, lastIndexOf, atFormatting, conversions, type checking, index lookups.

Final Thoughts

A few friendly tips to keep in mind as you explore javascript arrays:

  • Don’t stress about memorization, focus on understanding what each method does and practicing it in small projects.
  • Use mutating methods when you intentionally want to change the original array.
  • Use non-mutating methods to write safer, predictable code.

Remember, it’s not about knowing every method; it’s about knowing the right one for the job and using them effectively. Take it step by step, and your array skills will grow naturally.

Happy learning and thank you for reading!