Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
.filter return empty array but same condition work with .map

I'm doing a simple search bar on react native

I've got some dummy NftDatas that look like this :

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

I've got a handleSearch() function which compare the user input to the names in the list :

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

But if I map the array and verify the exact same condition it works perfectly fine :

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 ...]

Even if my app now works fine I wonder what I did wrong with my .filter function

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda