3 Minutes with Kent

Rarely forEach, normally for..of


Listen Later

Hey friends. So today I wanted to talk about looping over a raise and stuff

like that. And pretty much I'm mostly want to talk about for loops. Early
on in my software developer career that's pretty much exclusively how I
looked over things and I learned about filter and map and reduced and all
of those things and for each and all that and I went full in on that stuff.

More recently, I've been getting into using four of loops for stuff. And I

find that to work out really nicely.To the point where I don't think you'll
ever ever catch me use a for each on an array anymore I and like I can't
think of a scenario where that would be more simple than just doing a four
of loop.

With potentially the exception of you've got a function over here already

to find and you're just gonna pass it as the argument to for each. Maybe
that I guess could make sense but most of the time I'm just gonna be using
a forever. So anyway, I Yeah, I don't really have much more to say about
that.

It's just kind of.Something interesting to think about and I do have a blog

post actually about using map and filter versus reduce and a regular old
sea style loop where you have the index and everything like that. And so
you could go take a look at that if you're interested in diving little
deeper, it even has an egg-head video on there.

But yeah, just look at my blog look for reduce or filter. You'll find it on

there. But yeah, I find myself like early on. I used those sea style loops
and,Then and full on a raise and now I'm kind of yeah between array
methods, sometimes I'll use reduced but not often I'm mostly on filter and
map.

If I really need performance gains of using reduced then I'll go with that

just fine but anyway hope that is interesting and useful and insightful. If
you haven't been using four ofs and you've been finding you're using for
each then yeah, go ahead and give a four of trying they're pretty great.

Thanks bye.

...more
View all episodesView all episodes
Download on the App Store

3 Minutes with KentBy Kent C. Dodds

  • 5
  • 5
  • 5
  • 5
  • 5

5

4 ratings