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

97
Views
Dynamically generated object property undefined

I have this dynamically generated object whose properties displayed undefined. I don't seem to understand why it happened.

Pls help.

here is the code.

let submittionObject = {};
let submit = {};

let theSubmission = ['english', 'mathematics', 'r1Submitted', 'biology'];

    const theSubmit = theSubmission.map((item, index) => {
    if(item.indexOf('Submitted') !== -1){
        console.log(item.indexOf('Submitted'))
        submit = {...submittionObject, [item]: false};
    }else{
        submit = {...submittionObject,  [`r${index+1}Submitted`]: true};
    }
    return submit;
});



        const {r1Submitted, r2Submitted, r3Submitted, r4Submitted} = theSubmit;

The value of the destructured object should be a boolean of true or false but it instead displayed undefined

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Looks like you are looking for something like this :

const theSubmission = ['english', 'mathematics', 'r1Submitted', 'biology'];
const submittionObject = {};

theSubmission.forEach((subject, index) => {
  submittionObject[theSubmission[index]] = (subject.indexOf('Submitted') !== -1) ? true : false;
});

console.log(submittionObject);

about 4 years ago · Juan Pablo Isaza Report

0

map returns an array and property 'r1Submitted' and so on does not exist on an array. You will need to loop over the array to find the item with that property on it.

const r1Submitted = theSubmit.find(i => i.r1Submitted)

about 4 years ago · Juan Pablo Isaza Report

0

Return a boolean in the callback. Try this,

let submittionObject = {};
let submit = {};

let theSubmission = ['english', 'mathematics', 'r1Submitted', 'biology'];

    const theSubmit = theSubmission.map((item, index) => {
    if(item.indexOf('Submitted') !== -1){
        console.log(item.indexOf('Submitted'))
        item = false;
    }else{
        item = true;
    }
    return item;
  });
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!