Answers for "drill into tree to find key javascript"

0

drill into tree to find key javascript

let search = (needle, haystack, found = []) => {
  Object.keys(haystack).forEach((key) => {
    if(key === needle){
      found.push(haystack[key]);
      return found;
    }
    if(typeof haystack[key] === 'object'){
      search(needle, haystack[key], found);
    }
  });
  return found;
};
Posted by: Guest on March-15-2021

Code answers related to "drill into tree to find key javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language