Array PDF
Array PDF
Top 14 JavaScript
Array Methods
Every Beginner Must Know
length is 6
😊 😱 😡 😴 🤔 😃
0 1 2 3 4 5
index
value
Page 1
JavaScript tips
.push( )
What it does: Adds elements to the end of an array.
Use case: When you need to expand your array.
Page 2
JavaScript tips
.pop( )
What it does: Removes the last element and returns it.
Use case: When you want to remove or process the last
item.
Page 3
JavaScript tips
.shift( )
What it does: Removes the first element and returns it.
Use case: When you need to dequeue or process the first
item.
Page 4
JavaScript tips
.unshift( )
What it does: Adds elements to the beginning of an array.
Use case: When you want to prepend items.
Page 5
JavaScript tips
.slice( )
What it does: Returns a shallow copy of a portion of an
array without modifying the original.
Use case: When you need a subset of an array.
Page 6
JavaScript tips
.splice( )
What it does: Adds, removes, or replaces elements in an
array.
Use case: When you need to modify the array directly.
Note:
In this case, the first 1 is the index where the change starts (the second element),
😱
and the second 1 specifies how many elements to remove (one element, ""). It
😃 😊 😃 😡
then replaces the removed element with " ", resulting in the array [" ", "", ""].
Page 7
JavaScript tips
.map( )
What it does: Transforms every element in an array and
returns a new array.
Use case: When you want to apply the same function to
each item.
Page 8
JavaScript tips
.filter( )
What it does: Filters the array based on a condition and
returns a new array.
Use case: When you want only specific items.
Page 9
JavaScript tips
.reduce( )
What it does: Reduces the array to a single value by
applying a callback function.
Use case: When you need a summary value (e.g.,
concatenation).
Page 10
JavaScript tips
.forEach( )
What it does: Executes a provided function once for each
array element.
Use case: When you want to iterate through an array but
don’t need a new array.
Page 11
JavaScript tips
.find( )
What it does: Returns the first element that satisfies a
condition.
Use case: When you’re looking for one specific item.
Page 12
JavaScript tips
.findIndex( )
What it does: Returns the index of the first element that
satisfies a condition.
Use case: When you need the position of an item.
Page 13
JavaScript tips
.includes( )
What it does: Checks if an array includes a certain value.
Use case: When you want to verify the existence of an
item.
Page 14
JavaScript tips
.sort( )
What it does: Sorts the elements of an array in place.
Use case: When you need a sorted array.
Page 15
JavaScript tips
Page 16