Filtering

Keyboard Shortcuts

This video discusses filter, a Lodash function used to grab certain elements from an array of data. We show how instead of using a for loop to cycle through an array, we can use filter, leading to cleaner, more robust code.

- [Narrator] The next function is called filter.…Filter is used when you want only the elements…in an array that fits some kind of criteria.…For example, if you wanted only the even numbers…from an array of numbers or only the employees…that make more than a certain amount per year.…The syntax of filter is similar to map.…The only difference is that instead of passing…at function that returns a value…for each element in an array,…you pass at a function that returns…either true of false for each element.…If the function that you pass returns true…for a given element,…then that element is included in the final array.…

Otherwise, it's left out.…Now, let's take a look at how filter is used.…So, let's use the example I just mentioned.…Let's say that we have a simple array of numbers…and we want only the even numbers from the array.…Again, here's the typical procedural way to do this…using a for-loop to push elements on to another array.…Let's convert this to use filter instead.…First, let's remember to include lodash,…

Resume Transcript Auto-Scroll

Author

Released

7/14/2017

Functional programming is a clean, robust alternative to the more typical procedural style of programming. In this course, learn about the functional concepts at the heart of many JavaScript frameworks and programs. Shaun Wassell begins by explaining what functional programming is, exactly, and how it compares to object-oriented programming. He then covers the basics of functional programming in JavaScript, discussing concepts such as higher-order functions and closure. He then moves on to mid-level topics, touching on JavaScript array methods and callbacks. Finally, he dives into advanced concepts, including partial application and recursion.