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

160
Views
How to retrieve a array/object data values using HOF?

Does anybody can help me how to retrieve array/object values using High Order Functions?

this is my data, the block repeats several times and I need to retrieve the resident names.

species: [
    {
      id: lionId,
      name: 'lions',
      popularity: 4,
      location: 'NE',
      availability: ['Tuesday', 'Thursday', 'Saturday', 'Sunday'],
      residents: [
        {
          name: 'Zena',
          sex: 'female',
          age: 12,
        },
     etc

I have tried the following code, but only can get the residents group, and I need to extract only residents names.

return species.map((e) => e.residents);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your map method will return an array of arrays with resident objects inside of it. Use flatMap to flatten the data to a single array of resident objects.

Then map over the resident objects and return the name property for each resident. This will give you an array of resident names.

const species = [{
  id: '',
  name: 'lions',
  popularity: 4,
  location: 'NE',
  availability: ['Tuesday', 'Thursday', 'Saturday', 'Sunday'],
  residents: [{
    name: 'Zena',
    sex: 'female',
    age: 12,
  }, ],
}];

const residents = species.flatMap(specie => specie.residents);
const residentNames = residents.map(resident => resident.name);
console.log(residentNames);

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!