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

81
Vistas
Returning key values from an array of object Javascript

Hi I am 99% there with the code below but I need this array of objects to return:- 'Bear', 'Minu', 'Basil', 'Hamish' instead it returns Bear,MinuBasil,Hamish any ideas?

    gatherPets([{ name: 'Malcolm', pets: ['Bear', 'Minu'] },{ name: 'Caroline', pets: ['Basil', 
    'Hamish'] },]);

    function gatherPets(people) {
      let newArray=[];
      for (let i=0; i <=people.length; i++ ) {
        newArray = newArray +people[i].pets
      }
      return (newArray)
    }
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

I hope this code helping you

array.flatMap(o=>o.pets)
about 4 years ago · Juan Pablo Isaza Denunciar

0

You could use the Array#flatMap method for this.

export function gatherPets(pople){
  return people.flatMap(p => p.pets);
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

try this

gatherPets([{ name: 'Malcolm', pets: ['Bear', 'Minu'] },{ name: 'Caroline', pets: ['Basil', 
'Hamish'] },]);

function gatherPets(people) {
let newArray=[];
for (let i=0; i <people.length; i++ ){
newArray.push(...people[i].pets);    
}
return (newArray)
}
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