Array.prototype.reduce in JavaScript by example

Share this video with your friends

Send Tweet

Let's take a closer look at using Javascript's built in Array reduce function. Reduce is deceptively simple and when harnessed correctly can achieve very powerful results. By leveraging reduce, we can answer a variety of questions on a single, simple data set. In this lesson, we'll look at how you might use Array.prototype.reduce to:

  • Sum an array of numbers
  • Reduce an array of objects to a sum of a given property
  • Group an array of objects by key or a set of given criteria
  • Count the number of objects in an array by key or a given set of criteria
Alex
Alex
~ 9 years ago

i wonder what is this editor that you use to produce your episodes? You all seem to use different editors, unless it is different settings of WebStorm?

Erik Aybar
Erik Aybar(instructor)
~ 9 years ago

Hi Alex,

For this episode (and many others) the editor is JSBin. It looks like the JSBin link is broken, but you can view and play with the source/editor for this lesson here: http://jsbin.com/sapafe/latest/edit?js,console

We do tend to use a variety of editors since different lessons have different requirements and as instructors we have our own preferences. JSBin is great for small prototypal stuff and has great ES6/Babel support.

Personally, I use WebStorm combined with SublimeText day-to-day (you can peak at my Sublime setup here: https://egghead.io/lessons/ecmascript-6-es6-modules-es2015-import-and-export and my WebStorm setup here: https://egghead.io/lessons/misc-webstorm-installing-custom-color-schemes-dayleress-colour-schemes)

Alex
Alex
~ 9 years ago

jsbin is pretty cool. I did not know about it. thanks.