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

90
Vistas
Unexpected undefined result

I'm trying to go through an array of objects to extract two properties to another object. I have the following function to achieve this. While it works for the nested property correctly, I cant extract non-nested property and keep getting undefined.

const formatPhonesArray = (array) => {
  console.log(array);
  let resultArray = [];
  for (const phone of array) {
    resultArray.push({
      operator: phone.operator.name,
      phone: phone.number,
    });
  }
  console.log(resultArray);
  return resultArray;
};

And I have the following array

[
  {
    _id: new ObjectId("6190ecde73b2623593666fbb"),
    number: '+38(067)341-32-92',
    operator: {
      _id: new ObjectId("616090760a30fb3f993b61b5"),
      name: 'Київстар',
      codes: [Array],
      __v: 0
    }
  }
]

But somehow it yelds this [ { operator: 'Київстар', phone: undefined } ] while I expect [ { operator: 'Київстар', phone: '+38(067)341-32-92'} ] and I can't figure out why.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No problem in your code I got this result

[
  {
    "operator": "Київстар",
    "phone": "+38(067)341-32-92"
  }
]

Its working

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