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

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

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