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

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

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 Relatório

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 Relatório

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 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