This is my variable tree:
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)
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');