The Array filter method

InstructorJafar Husain

Share this video with your friends

Send Tweet

One very common operation in programming is to iterate through an Array's contents, apply a test function to each item, and create a new array containing only those items the passed the test. For example, let's say you wanted to loop through an array of stocks and select only those with the price larger than a certain value. In this lesson we will demonstrate how to use the Array's filter method to easily perform this operation with less code than a loop would require.

Will
~ 9 years ago

Very helpful! I should've watched this a long time ago.

jd17ortiz@gmail.com
~ 9 years ago

Hi, great content!

I'd like to know if the use of filter instead of regular "IF" is better for performance or is just to keep code clean?? Thanks!

HaveF
~ 8 years ago

I have no idea why always use console.log(JSON.stringify(....)) instead of console.log(...). Does it has any extra benefits?

Jafar Husaininstructor
~ 8 years ago

Only benefit is that the output is fully expanded. It's good for lessons.

Andrejb
~ 8 years ago

Jafar Husain, you are the worst instructor that i have found here. Very awful examples, not for beginners. Your examples doesn't interested for beginners like me. Post the more simple samples.

Vishwas Chouhan
~ 7 years ago

What is the predicate param you passed when defining the filter method.

TINYHR; INC, 200 W Thomas Street - Suite 100, Seattle, WA
~ 7 years ago

Are map, forEach and filter considered with Asynchronous function? Could you please explain for me about this?