0% found this document useful (0 votes)
1 views

001 Array Callback Methods

The document explains various array callback methods in JavaScript, including forEach, map, filter, find, reduce, some, and every. It emphasizes the use of arrow functions as a compact alternative to regular function expressions. Additionally, it provides insights on how to sort arrays using a comparison function.

Uploaded by

markmaksi97
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)
1 views

001 Array Callback Methods

The document explains various array callback methods in JavaScript, including forEach, map, filter, find, reduce, some, and every. It emphasizes the use of arrow functions as a compact alternative to regular function expressions. Additionally, it provides insights on how to sort arrays using a comparison function.

Uploaded by

markmaksi97
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
You are on page 1/ 23

ARRAY

CALLBACK
METHODS
ARRAY
CALLBACK METHODS
Arrays come with many
built-in methods that
accept callback functions
Now that we've covered
callbacks, we can learn
these methods!
SUPER USEFUL!
GOALS
Use the new arrow function syntax
Understand and use these methods:
forEach
map
filter
find
reduce
some
every
FOREACH
Accepts a callback
function.
Calls the function
once per element
in the array.
MAP
Creates a new array with
the results of calling a
callback on every element
in the array
MAP
ARROW
FUNCTIONS!
ARROW
FUNCTIONS
"syntactically compact alternative"
to a regular function expression
ARROW
FUNCTIONS
IMPLICIT RETURN
All these functions do the same thing:
FIND
returns the value of the first element in the array
that satisfies the provided testing function.
FILTER
Creates a new array with all elements that pass the
test implemented by the provided function.
EVERY
tests whether all elements in the array pass the
provided function. It returns a Boolean value.
SOME
Similar to every, but returns true if ANY of
the array elements pass the test function
REDUCE
REDUCE
REDUCE
REDUCE
REDUCE
REDUCE
REDUCE
REDUCE
REDUCE
REDUCE
REDUCE
Executes a reducer function
on each element of the array,
resulting in a single value.
SUMMING AN ARRAY
FINDING MAX VAL
INITIAL VALUE
TALLYING
SORT PT. 2
arr.sort(compareFunc(a,b))
If compareFunc(a,b) returns less than 0
Sort a before b
If compareFunc(a,b) returns 0
Leave a and b unchanged with respect to
each other
If compareFunc(a,b) returns greater than 0
Sort b before a
SORT

You might also like