This week focus was on Advanced Array Methods from Colt Steele The Advanced Web Developer Bootcamp.
-forEach
-map
-Filter
-Some
-Every
-Reduce
forEach
Iterates through an array
Runs a callback function on each value in the array
returns 'undefined'
forEach Always returns undefined
map
Creates a new array
Iterates through an array
Runs a callback function for each value in the array
Adds the result of that callback function to the new array
map Always returns a new array of the same length
Filter
Creates a new array
Iterates through an array
Runs a callback function on each value in the array
If the callback function returns true, that value will be added to the new array
If the callback function returns false, that value will be ignored from the new array
The result of the callback will Always be a boolean
Some
Iterates through an array
Runs a callback on each value in the array
If the callback returns true for at least one single value, return true
Otherwise return false
The result of the callback will always be a boolean
Every
Iterates through an array
Runs a callback on each value in the array
If the callback returns false for any single value, return false
Otherwise, return true
The result of the callback will always be a boolean
Reduce
Accepts a callback function and an optional second parameter
Iterates through an array
Runs a callback on each value in the array
The first parameter to the callback is either the first value in the array or the optional second parameter
The first parameter to the callback is often called accumulator
The returned value from the callback becomes the new value of accumulator
Top comments (0)