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

332
Views
How to build names from related Lavels?

I like to build a list of names to an array. It needs to find the name from Level1 and then go through the chain to Level3. If it does not match from Level1 then try Level2, if still no match then try to get the Name from Level3

For example Ouput:

getNames("Office") to return ["Office", "Microsoft", "Software"]

getNames("Apple") to return ["Apple", "Software"]

getNames("Tesla") to return ["Tesla", "Car"]

Data

 const data =   {
        "Level1": [ { "Names": [ "Office" ], "Level": "Level2#Microsoft" } ],
        "Level2": [ { "Names": [ "Apple", "Microsoft" ], "Level": "Level3#Software" }, { "Names": [ "Tesla" ], "SubLevel": "Level3#Car" }],
        "Level3": [ { "Names": [ "Software" ] }, { "Names": [ "Car" ] } ]
    }

I am struggling with how to get data to the next level without writing many if conditions?

Incomplete usage:

function getNames(name) {
    const namesBuild = [];

    const foundName = data.Level1.find(row => {
        return row.Names.find(rowName => rowName === name)
    });
    
    if (foundName) {
        namesBuild.push(name);
        const subLevel = foundName.Level.split("#");

        const catLevel = subLevel[0];
        const catName = subLevel[1];

        // How to continue to find next chain from object without many if conditions?
    } else {
        // attempt to find next level Level2, if not found then try Level3
    }

    return namesBuild;
    }
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!