Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!