My understanding of JavaScript filter

Srikanth Athikari
2 min readApr 12, 2022

Yes, Everyone of us can code. I started learning programming by doing side projects and learning from books, videos and blogs, they are my teachers. It was scary for me hearing the big terminology, especially in programming. But, once I started learning one at a time, reading about it, working on smaller examples, implementing them on side projects, I felt it was just the terminology or fear of change or learning new things that scared me the most and with most of us. To my understanding, we are capable enough to learn, work and do anything that is man-made. Maybe the amount of time it takes to learn and master might vary from person to person, but 100% possible. I would like to explain to readers about JavaScript filter. I wrote this blog more for my understanding and I am happy if it helps others.

At the core, we can relate the concept of the filter with the image added above. Yes, it is as simple as the filter we see. We first add a paper-filter to the coffee machine, add the coffee powder into the paper-filter, and pour water into the filter. Meaning, we are pouring water and expecting coffee in return avoiding the unwanted, up to a limit that we are specifying. Let me convert this into code.

z

Key takeaways

  1. The filter method does not change the original array
  2. A new array is formed with the filter method
  3. Returned value is an array
  4. Filter does not work on empty elements

If you think I made it easy, I would love to see it in the comments.

--

--