Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is it something wrong in my code that's only filter the data once, and after that I got no data when I search it again.


What I have tried:

const results = data?.map(singleData => {
    singleData.websites = singleData.websites.filter(website =>
      website.name.toLowerCase().includes(searchedQuery.toLowerCase())
    );
Posted
Updated 17-Feb-22 5:44am

1 solution

Your code is overwriting the websites property of the items in your source array with a filtered list.

Change it to return the filtered list instead:
JavaScript
const results = data?.map(singleData => singleData.websites.filter(website => website.name.toUpperCase().includes(searchQuery.toUpperCase())));
NB: You should generally normalize strings to upper-case for comparison, to avoid the "Turkish i" problem[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900