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

149
Vistas
To get index or matching values from Nested Array of values : Javascript/Typescript/Lodash

I would like to find the matching values by iterating over each array of object values and also to find the path of the matching value. Property to be searched for the value is "subMenu" - It can be either an object or an array of strings.

Example Array :

  mainArray = [
    {
      name: 'mainMenu1',
      subMenu: [
        {
          name: 'subMenuLevel1',
          subMenu: [
            {
              name: 'subMenuLevel2',
              subMenu: ['AAA', 'BBB'],
            },
            {
              name: 'subMenuLevels',
              subMenu: ['CCC'],
            },
          ],
        },
      ],
    },
    {
      name: 'mainMenu2',
      subMenu: ['MMM'],
    },
  ];

Value to be searched \ Input: AAA

I want to find where the value "AAA" is presented by traversing through all the subMenu property in the available nested array of objects ? If "AAA" matches with any of the subMenu Array values may I know how can I take the path of the value as well like the expected output below.

Example Output:

level3 = AAA , 
level2 = subMenuLevel2,
level1 = subMenuLevel1,
mainLevel = mainMenu1
about 4 years ago · Juan Pablo Isaza
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