Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda