[Go to site: main page, start]

0% found this document useful (0 votes)
21 views4 pages

JavaScript Array Methods Guide

This document is a cheat sheet for JavaScript array methods, categorizing them into sections such as Iteration/Transformation, Add/Remove Elements, Search/Index, Sort/Reverse, and Other Useful methods. Each method is described with its functionality and includes examples for better understanding. It serves as a quick reference for developers working with arrays in JavaScript.

Uploaded by

satyamsinha920
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

JavaScript Array Methods Guide

This document is a cheat sheet for JavaScript array methods, categorizing them into sections such as Iteration/Transformation, Add/Remove Elements, Search/Index, Sort/Reverse, and Other Useful methods. Each method is described with its functionality and includes examples for better understanding. It serves as a quick reference for developers working with arrays in JavaScript.

Uploaded by

satyamsinha920
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Array Methods Cheat Sheet

Category
Method
Description
Example
Iteration / Transformation
forEach
Execute function for each
element
[1,2,3].forEach(n =>
Iteration / Transformation [Link](n))
map
Transform elements & return
new array
[1,2,3].map(n =>
Iteration / Transformation n*2) -> [2,4,6]
filter
Select elements based on
condition
[1,2,3].filter(n =>
Iteration / Transformation n>1) -> [2,3]
reduce
Reduce to a single value
[1,2,3].reduce((sum,
Iteration / Transformation n)=>sum+n,0) -> 6
reduceRight
Reduce from right to left
[1,2,3].reduceRight(
Iteration / Transformation (sum,n)=>sum+n,0)
some -> 6
True if any element matches
[1,2,3].some(n=>n>
2) -> true
Iteration / Transformation
every
True if all elements match
[1,2,3].every(n>0)
Iteration / Transformation -> true
find
First element matching
condition
[1,2,3].find(n=>n>1)
Iteration / Transformation -> 2
findIndex
Index of first matching element
[1,2,3].findIndex(n=
Add / Remove Elements >n>1) -> 1
push
Add to end
[1,2].push(3) ->
Add / Remove Elements [1,2,3]
pop
Remove from end
[1,2,3].pop() -> [1,2]
Add / Remove Elements
unshift
Add to start
[2,3].unshift(1) ->
Add / Remove Elements [1,2,3]
shift
Remove from start
[1,2,3].shift() ->
Add / Remove Elements [2,3]
splice
Add/remove at index
[1,2,3].splice(1,1,99
) -> [1,99,3]
Add / Remove Elements
slice
Copy portion
[1,2,3,4].slice(1,3)
Add / Remove Elements -> [2,3]
concat
Merge arrays
[1,2].concat([3,4])
Search / Index -> [1,2,3,4]
indexOf
First index of value
[1,2,3].indexOf(2) ->
Search / Index 1
lastIndexOf
Last index of value
[1,2,2].lastIndexOf(
Search / Index 2) -> 2
includes
Check if value exists
[1,2,3].includes(2)
Sort / Reverse -> true
sort
Sort array (mutates)
[3,1,2].sort() ->
Sort / Reverse [1,2,3]
reverse
Reverse array (mutates)
[1,2,3].reverse() ->
Other Useful [3,2,1]
join
Combine to string
[1,2,3].join('-') ->
'1-2-3'
Other Useful
flat
Flatten nested arrays
[1,[2,3]].flat() ->
Other Useful [1,2,3]
flatMap
Map & flatten one level
[1,2].flatMap(x=>[x,
Other Useful x*2]) -> [1,2,2,4]
fill
Fill array with value
Array(3).fill(0) ->
Other Useful [0,0,0]
copyWithin
Copy part inside itself
[1,2,3,4].copyWithin
(0,2) -> [3,4,3,4]

You might also like