I am using a recursive function and currently declared my_json as an array of strings and then when run recursively as a type 'any', but obviously that's not a perfect solution. my_json has a specific type, but when the function is run recursively it changes its type to a index key. How can I fix this? Any advice appreciated.
const findSomething = (my_json: any, value: string): boolean => {
let exist = false;
Object.keys(my_json).some(key => {
exist =
typeof my_json[key] === 'object'
? findSomething(my_json[key], value)
: my_json[key] === value;
return exist;
});
return exist;
};
findSomething(my_json, '123')
my_json:
{
"aaa": [
"123",
"456",
"789"
],
"bbb": [
"000",
"001",
"002"
],
}