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

100
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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