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

144
Vistas
How to object property parse to nested array array using javascript?

It receives data from the request body in the following format. Properly I have to insert it into the database but the format is not correct.

{
  name: '123',
  description: 'Dev',
  "item_variants[0]['name']": '23434',
  "item_variants[0]['quantity']": '12334',
  "item_variants[0]['unit_price']": '123123',
}

And how to transform the following format? Everyone's answers help me some ideas. Thank you

{
      name: '123',
      description: 'Dev',
      item_variants: [
         {
            name: '23434',
            quantity: '23434',
            unit_price: '23434',
         }
      ]
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In express, after getting this form body you have to store this response in any variable and reformate this response after formatting you can save it into the database.

try {
  let inputs = req.body;

  inputs = {
    name: inputs.name,
    description: inputs.description,
    item_variants: [
      {
        name: item_variants[0].name,
        quantity: item_variants[0].quantity,
        unit_price: item_variants[0].unit_price,
      },
    ],
  };

  // NOW you can save this formatted version into the database

  const result = await Product.save(inputs);
} catch (e) {
  console.log(e);
}

In item_variants name, quantity, unit_price you might change digging and getting value.

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