Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 12, 2021 09:57 pm GMT

Filter array with multiple conditions

Ive been working on my first "React" project and this project I build is a "Park Browser" which is basically an app that helps you search for a specific national park in USA either by address, city or state.

Alt Text

It was really hard to understand how can I filter through an array with multiple conditions and also pass those conditions from a child component to parent.
Of course I googled it right away and I found it on "stackoverflow" (credit to Narendra Jadhav from stackoverflow).

Alt Text

Parent:
Alt Text

Child:
Alt Text

It seemed like its working but there was another problem,
If you searched for a park by one of the conditions it worked but if you wanted to use another condition or use a different one it will not change the search, Until i found the "continue" method in JS.

Alt Text

It is pretty simple what the "continue" method does,
If there are no filters to filter "continue" to the next "if" statement that will show me the parks that I am looking for by filter and if there are no results just return and empty search.

It helped me a-lot with understanding how to pass data from child to parent and how to use multiple conditions to filter and array.

I hope this post helped you with your errors,
Good Luck!


Original Link: https://dev.to/itushthegiant/filter-array-with-multiple-conditions-5928

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To