I have a Class containing keys, values and children like this
class Container{
key: string,
value: string,
children: Container[]
}
function searchKey(container: Container, key:string){
if (container.key == key) {
return container;
}
else if (container.children.length>0){
for (let child of container.children) {
let found = searchKey(child, key);
if (found != null) {
return found;
}
}
}
return null;
}
Input which I will be supplying to searchKey() function would be an array with deep objects and I want to get value for the supplied key parameter. But the current searchKey() function would not accept an array. How to make it to work with an array as input?