Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda