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

130
Vistas
How to filter values of an array inside an array?

I will describe the situation for more clarity. I have an array like this

animalsArray = {
animalID : number,
animalName: string,
animalDescription: string,

animalChild: animalsArray[]

}

Now I have to filter these animals using animalName from user input by textfield. Some animals can have n number of animalChild or non at all or animalChild can have another animalChild inside it.

I already have a code like this

public animalsArray:animalsArray[]

    this.filteredanimalsArray.next(
                this.animalsArray.filter(item => (item.animalName.toLowerCase().indexOf(search) > -1))
            );

To filter the main animalsArray and it works fine but the user input doesn't go through the child arrays.

How can I solve this problem? Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Maybe you could use recursivity like this :

function filterAnimals(animals, name) {
    return animals.filter(animal => {
        const matching = animal.animalName.toLowerCase() === name.toLowerCase();
        const hasChildMatch = Array.isArray(animal.animalChild) && filterAnimals(animal.animalChild, name).length > 0;
        return matching || hasChildMatch;
    });
}

const search = 'leon';
const filterdAnimals = filterAnimals(animalsArray, search);
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