Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
.filter devuelve una matriz vacía pero la misma condición funciona con .map

Estoy haciendo una barra de búsqueda simple en reaccionar nativo

Tengo algunos NftData ficticios que se ven así:

 [ { name: "Lorem ipsum", ... }, { name: "dolor sit amet", ... }, { name: "consectetur adipiscing", ... }, { name: "elementum dolor", ... }, { name: "sapien eu porttitor", ... }, ]

Tengo una función handleSearch() que compara la entrada del usuario con los nombres en la lista:

 const handleSearch = (value) => { const filteredData = NFTData.filter((item) => { item.name.toLowerCase().includes(value.toLowerCase()); }); console.log(filteredData); }; //Return an empty array no matter what value the user inputted

Pero si mapeo la matriz y verifico exactamente la misma condición, funciona perfectamente bien:

 const handleSearch = (value) => { let filteredData2 = []; NFTData.map((item) => { if (item.name.toLowerCase().includes(value.toLowerCase())) { filteredData2.push(item.name); } }); console.log(filteredData2); }; // For user input "lor" return ["Lorem ipsum", "dolor sit amet", etc ...]

Incluso si mi aplicación ahora funciona bien, me pregunto qué hice mal con mi función .filter

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!