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

105
Vistas
how can I use sub-array inside of the main array javascript

I want to use values from "property: []" sub-array inside the "name: id" section but it gives

"Cannot read property 'property' of undefined" error. How can I prevent the error and solve this?

Basically I want to push datas inside the subarray than use it inside the main array how can I do that?

function generateObject(id, Samplelist) {

  Object[id] = {
    name: Object[id].property[0],
    property: []
  };

  Samplelist.forEach((list, i) => {
    Object[id].property.push({
      type: types[order[i]],
      quality: qual[fileToMap],
    });
  });

}

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

0

You can not assign something before initializing it. First create the object, populate the property and then use it to assign other properties.

  function generateObject(id, lists) {

  Object[id] = {
    name: undefined, // you can not existact somethng before adding it
    property: []
  };

  Samplelist.forEach((list, i) => {
    Object[id].property.push({
      type: types[order[i]],
      quality: qual[fileToMap],
    });
  });
  
 // after property is assinged value in foreach you can proceed to assign it  
Object[id].name = Object[id].property[0];  

}
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