map(), reduce(), some(), every(): The 4 Arrays Methods That Stopped Me from Using forEach()

preview_player
Показать описание
There's so much more to learn beyond just how to use a programming language. When I first started writing JavaScript, I relied heavily on the array method forEach. But little did I know there were better, more declarative array methods I code be using in my projects.

In this video, I walk through the map, reduce, some, and every array methods so you know how to use them in your projects. The goal of this video is to inspire you to use the other array methods before forEach.

Often times, the name forEach can be too generic to first-time readers of your code. Yes, you know that you are looping over an array, but why? Do you want to generate a new array, filter some data out, or find a single item? There are array methods that not only iterate over a list but also serve a specific purpose.

Timestamps:
0:00 Intro
0:49 map() - Generate a New Array
2:33 reduce() - Return a Unique Single Value
6:04 some() - Determine if At Least One Type of Element Exists
7:19 every() - Determine if All Elements are the Same

== Let's Connect ==

== Who I Am ==
I'm Ijemma, a frontend software engineer currently working in New York City. I make videos on all things JavaScript and, more broadly, frontend web development.

#javascript #webdevelopment #softwareengineer
Рекомендации по теме
Комментарии
Автор

THANK YOU 100 times, I like your videos, it's not just reciting a mdn or w3 schools to us,

tonytony-fcgq
Автор

Fantastic job on this! The examples are practical and spot on. The video is perfect. Really well done!

jherr
Автор

Ijemma your content is pure gold. I personally turned on notifications in anticipation of your next upload. Thank you for all the effort you have put in so far.
You are appreciated :)

aaeonCodes
Автор

Ijemma, Thank you so much for your videos. You're a wonderful teacher and an inspiration to all of us. As so many others have said, your videos are pure gold (this being the second one that I have watched). As you say, the map, reduce, some and every methods are so much easier to understand than the foreach method. A further simplification that they bring is that their result can (and should) be stored as a const (i.e. immutable) value, thus obviating the need to use a mutable let variable, as in the case of foreach. The latter is yet another complexity that we don't have to rack our brains over!

posfr
Автор

I'd really love to hear you cover thigns like monoids, monads (all types? maybe? : 🤔), contracts, asserts, short circuit evals, anti-patterns, design patterns, all the things 😃 really enjoy your vids. Oh also would be great if you could throw a more "real-world" example, I know these are hard to come by but maybe a really good place where you found its usage, and other solutions would have been far worse or just suboptimal and discuss pros and cons. Anyway keep up the great content.

hugodsa
Автор

Great vid! I think every developer must have a list of sort of "bad" practices. Readability and simplicity are quite important nowadays

vitiok
Автор

This is a kind of functional programming. I enjoy using it in kotlin. Thumbs up for awesome videos you create.

odifek
Автор

Super amazing, I found you from twitter 🙌🎉

Developerorium
Автор

Such a great explanation, thanks for sharing. 👩🏻‍💻

karlstenator
Автор

Thank you for this video! I find your explanation really helps me understand why each of the 4 array methods are preferred over the forEach() method. Especially, when it comes to writing our own code for other's to decipher and vice versa. Please continue to share your knowledge! <3

jadengocnguyen
Автор

Great video. I enjoyed this. Examples are spot on.

JuliaPottinger
Автор

You have excellent content. Pls keep making more videos. If you shift to Python I will sponsor you 😊

elatedbento
Автор

I really like array methods but I know that a for loop is better for performance. Because chaining maps and such, copies the array everytime and you need to create a closure object "() => {}" which also needs to be garbage collected.

I really like how Rust transforms usage of chained array methods into 1 for loop under the hood. Making this declarative approach a syntactic sugar, which is best of both world: declarative for humans, imperative for the compiler.

I hope the JS runtimes have or are going to optimise this.

BboyKeny
Автор

As a new SWE, this is really useful, thank you!

PabloSantos
Автор

07:49 the isAllUnderaged value will reflect the boolean check for the last element.

In your example, isAllUnderaged will be true even if there are elements with age>18

cryptodeveloper
Автор

when would you use forEach? What benefit does it have over a for loop

leedanilek