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,…
- What's functional programming?
- Functional vs. object-oriented programming
- First-class functions
- Higher-order functions
- Array functions
- Mapping, filtering, and reducing
- Simple callbacks
- Callbacks with arguments