Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda