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

87
Views
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 answers
Answer question

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