• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

js算法统计对象的层数

//测试数据

var testObj={

b: {

c: {

d: {

e: {}

}

},

c: {

d: {

e: {

d: {

a:

b: {

a:

}

},

a:

a:

a:

}

}

}

}

}

}

}

}

}

}

//封装方法

函数getObjLayer (obj={}) {

设结果=1;

常量计数=(param,level=0)={

结果=水平;

if(typeof param==='object' param!==null) {

对象.值(参数)。forEach(item={

//递归

if (typeof item==='object' item!==null) {

计数(项目,一级);

//调试器;

}

});

}

};

//手动启动

count(obj);

返回结果;

};

console.log('打印结果:',getObjLayer(test obj));//9

//更复杂的数据结构持续更新中

Link to comment
Share on other sites