📜  钻入树以查找关键的 javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:11.634000             🧑  作者: Mango

代码示例1
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;
};