The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

The Array filter method

The Array filter method

4:42
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.
Watch this lesson now
Avatar
egghead.io

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.

Avatar
Will

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

Avatar
jd17ortiz@gmail.com

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!

Avatar
HaveF

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

Avatar
Jafar

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

In reply to HaveF
Avatar
Andrejb

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.

Avatar
Vishwas

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

Avatar
TINYHR; INC,

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

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?