nowindxdw
11/15/2017 - 8:47 AM

深层嵌套打印对应key值

var _ = require("lodash");
var deepObj = {
  "a":{
    "b":{
      "c":{
        "d":1
      },
      "e":{
         "f":"hello word"
      }
    }
  }
};
var count = 0;
function getDepthOfData(data,depth){
    if(depth>0){
      depth = depth-1;
      count++;
      _.mapKeys(data,function(value, key){
        console.log("depth="+(count)+"key="+key);
        getDepthOfData(data[key],depth)
      });
    }
}
getDepthOfData(deepObj,4);