Filter method in javascript

 

Array.filter()

 

Filter method is used to filtering a array based on a condition. This method takes a callback method inside this method we need to give a condition if condition is true then return value see example bellow

 

Example

let myArray = [1, 2, 4, 3, 5, 6, 7, 8, 9]

let result = myArray.filter((x) => x <= 5);

console.log(result);

 

In this example we filter this array by using this condition number <= 5

About Author

Photo

Hi, I am Mahbub Hasan
Software Engineer

I am very much interested to share my programming
and development knowledge with the people.I will try
to update my blog everyday with new technology inshallah.

Thank You

For Visiting My Blog.

Contact Me