标签:children cti iso object child ceo fun ram key
// 比如这个a中,就有四层。如何算出这四层
const a = {
b: 1,
c() {},
d: {
e: 2,
f: {
g: 3,
h: {
i: 4,
},
},
j: {
k: 5,
},
},
};
function testLevel(param) {
const isObject = typeof param === ‘object‘ && !(param instanceof Array);
if (!isObject) return 0;
const level = 1;
let childrenLevel = 0;
Object.entries(param)
.map(([key, value]) => {
const valueLevel = testLevel(value, level);
if (valueLevel > childrenLevel) childrenLevel = valueLevel;
});
return level + childrenLevel;
}
标签:children cti iso object child ceo fun ram key
原文地址:https://www.cnblogs.com/qiqi715/p/10419697.html