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

113
Views
How can I find an array by object value?

This is my variable tree:

enter image description here

I want to find the element by it path. (in the case `Documents it is 0)

Like this myFolder gives me the correct output:

var myFolder = tree.childs[0]

But I do not have the key, I have only the path. I tried:

var myFolder = tree.map(Folder => Folder.path).indexOf('Documents/');

But I get an error message (implicity has an 'any' type)

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

const mainFolder = {
    childs: [
        { path: 'ExamplePathNameOne' },
        { path: 'ExamplePathNameTwo' },
        { path: 'ExamplePathNameThree' },
    ]
}

const folder = mainFolder.childs.find(c => c.path === 'ExamplePathNameOne');

But to fix your error message, either set "noImplicitAny": false in your tsconfig.json file or define an interface for the objects you are using, f.e. MainFolder and Folder.

interface MainFolder {
    childs: Folder[];
}

interface Folder {
    path: string;
}

const mainFolder: MainFolder = {
    childs: [
        { path: 'ExamplePathNameOne' },
        { path: 'ExamplePathNameTwo' },
        { path: 'ExamplePathNameThree' },
    ]
}

const folder = mainFolder.childs.find(c => c.path === 'ExamplePathNameOne');
about 4 years ago · Santiago Gelvez Report
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!