COMP3512
winter 2024
lec-js-02
The Next Stretch

⚠️
⚠️
13th: Midterm 2 (JS)
15th: Withdraw Deadline
⚠️
ExecuteProgram's

16 free lessons will get you through most of it - and lots of what we cover. Highly recommended.
let's talk about these things today:
◉ forEach()
◉ find()
◉ filter()
◉ sort()
◉ map()
5 Useful Array Methods
But first, let's talk about callbacks.
00-callbacks
In JS, functions are just "callable objects"! And like any object, you can use them as arguments in other functions.
What about arrow functions?
We'll get to them later in the course.
They're optional, but very common.
If you are keen to use them now, you have my blessing...and sympathies.
forEach()
forEach() is a "convenient" way to iterate through an array
01-forEach
find()
find() gets you the FIRST thing in an array that meets some criterion
02-find
filter()
filter() is just like find()...except now you get an array of 0 or more things back
03-filter


BRAIN BREAK
sort()
sort() works a lot like Collections.sort(), which you encountered in COMP2503
04-sort
map()
Think of map() as a magic wand that creates an array of things from an array of different things.
05-map
Warning: that analogy has some flaws....
lec-js-02
By Jordan Pratt
lec-js-02
functions | array methods
- 188