My understanding of JavaScript filter

Srikanth Athikari
2 min readApr 12, 2022

--

Yes, everyone can learn to code. I began my programming journey by working on side projects and learning from books, videos, and blogs. These resources became my teachers. Initially, the complex terminology in programming was intimidating. However, by focusing on one concept at a time, reading about it, practicing with small examples, and applying it to side projects, I realized that my fear stemmed from the unfamiliar terms and the challenge of learning new things.

In my experience, we all have the capacity to learn, work, and accomplish anything created by humans. The time it takes to learn and master a skill may vary from person to person, but it is entirely possible. I would like to share my understanding of the JavaScript filter function in this blog. While I wrote it primarily for my own comprehension, I hope it will also be helpful to others.

At its core, the concept of a filter can be related to the image above. It’s as straightforward as the filter we use in a coffee machine. First, we place a paper filter in the coffee machine, then add coffee grounds into the filter, and finally pour water through it. This process involves pouring water and expecting coffee in return, effectively filtering out the unwanted elements. Let me translate this concept into code.

z

Key takeaways

  • The original array remains unchanged.
  • A new array is created with the filtered elements.
  • The returned value is an array.
  • The filter method does not work on empty elements.

If this explanation simplified things for you, I’d love to read your feedback in the comments.

--

--

Srikanth Athikari
Srikanth Athikari

Written by Srikanth Athikari

A Human, Quality Engineer, Developer

Responses (1)