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

150
Vistas
How to get only the specific variation data to be display in react.js

I have created Shopping Cart the product name, image, price, and attributes are created in separate components. I'm getting an issue where I wanted to get only the specific product variation's attribute, but I got all product variation attributes as below image

enter image description here

Above show the product and its details, but the product attributes must show only its specific variation attributes but it shows all its variation attributes. below is the code and the MongoDB database structure of the product.

enter image description here

enter image description here

I don't know where I go wrong, plz help me. thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use the array filter method if you want to get a subset of the attributes. For example:

const res = {
  data: {
    VariationList: {
      Attribute: {
        Weight: 1,
        Length: 2,
        Width: 3,
        Hook: 4
      }
    }
  }
};

function getProductAttributes(data, filterList = []) {
  const entries = Object.entries(data.VariationList.Attribute);
  if (!filterList.length) return entries;
  return entries.filter((attr) => filterList.includes(attr[0]));
}

let output = getProductAttributes(res.data);
console.log(output); // [ [ 'Weight', 1 ], [ 'Length', 2 ], [ 'Width', 3 ], [ 'Hook', 4 ] ]

output = getProductAttributes(res.data, ['Weight', 'Length']);
console.log(output); // [ [ 'Weight', 1 ], [ 'Length', 2 ] ]
about 4 years ago · Juan Pablo Isaza Denunciar
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