Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!