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

164
Vistas
JavaScript / React Can't Filter An Array By Attributes

I'm currently trying to develop a filtering system for a React e-commerce store. I have a list of products in an array, however when trying to filter by the filters requested, I get errors that: Uncaught TypeError: Cannot read properties of undefined (reading 'includes').

This is the product schema:

const ProductSchema = new mongoose.Schema({
    title: {type: String, required: true, unique: true},
    description: {type: String, required: true, unique: true},
    image: {type: String, required: true},
    categories: {type: Array},
    sizes: {type: Array},
    color: {type: Array},
    price: {type: Number, required: true}

}, {timestamps: true});

This is the line of code where I'm trying to set filteredProducts to then map over each and display them:

useEffect(() => {
    // category &&
      setFilteredProducts(
        products.filter((item) =>
          Object.entries(filters).every(([key, value]) =>
            item[key].includes(value)
          )
        )
      );

  }, [products, category, filters]);

I think what it is saying is that 'colors' and 'sizes' are not attributes of the product. For reference, this is the filters object that is passed through: {colors: 'black', sizes: 's'}.

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