drill into tree to find key javascript

Solutions on MaxInterview for drill into tree to find key javascript by the best coders in the world

showing results for - "drill into tree to find key javascript"
Natan
02 Oct 2019
1let search = (needle, haystack, found = []) => {
2  Object.keys(haystack).forEach((key) => {
3    if(key === needle){
4      found.push(haystack[key]);
5      return found;
6    }
7    if(typeof haystack[key] === 'object'){
8      search(needle, haystack[key], found);
9    }
10  });
11  return found;
12};
13