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

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

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