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

115
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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