Save for later
8 Must-Know
JavaScript Array
Methods
@nacercodes
001
.forEach()
Executes a provided function once for each array
element.
const emojis = [' ', ' ', ' ']
[Link](emoji => {
[Link](`I love ${emoji}`)
})
Console
I love
I love
I love
@nacercodes
002
.map()
Creates a new array populated with the results of
calling a provided function on every element.
const emojis = [' ', ' ', ' ']
const result = [Link](emoji => {
return emoji + emoji
})
[Link](result)
Console
[ ' ', ' ', ' ' ]
@nacercodes
003
.filter()
Creates a new array with all elements that pass the
test implemented by the provided function.
const emojis = [' ', ' ', ' ', ' ']
const pet = [Link](emoji => {
return emoji == ' ' || emoji == ' '
})
[Link](pet)
Console
[ ' ', ' ' ]
@nacercodes
004
.concat()
Creates a new array by merging two or more arrays.
const fruits = [' ', ' ']
const vegetables = [' ', ' ']
const result = [Link](vegetables)
[Link](result)
Console
[ ' ', ' ', ' ', ' ' ]
@nacercodes
005
.find()
Returns the value of the first array element that
satisfies the provided test function, or undefined if
none does.
const emojis = [' ', ' ', ' ', ' ']
const moon = [Link](emoji => {
return emoji == ' '
})
[Link](moon)
Console
@nacercodes
006
.push()
Adds the specified elements to the end of an array.
const emojis = [' ', ' ', ' ']
[Link](' ')
[Link](emojis)
Console
[ ' ', ' ', ' ', ' ' ]
To add them to the beginning, use the .unshift()
method.
@nacercodes
007
.pop()
Removes the last element from an array and returns it.
const emojis = [' ', ' ', ' ']
const lastEmoji = [Link]()
[Link](lastEmoji)
[Link](emojis)
Console
[ ' ', ' ' ]
To remove the first one, use the .shift() method.
@nacercodes
008
.includes()
Determines whether an array includes a certain value
or not.
const emojis = [' ', ' ', ' ']
const hasSun = [Link](' ')
[Link](hasSun)
const hasStar = [Link](' ️')
[Link](hasStar)
Console
true
false
@nacercodes
Nacer Codes
@nacercodes
Save it or lose it. ️
s
de
rco
ce
na