更新时间:2021-11-22 23:03:10
在这种特定情况下,您可能需要使用以下代码:
In this specific case you'd might want to use this:
var baseObject = {
"value": 5,
"children": [{
"value": 18,
"children": [{
"value": 27,
"children": []
}, {
"value": 4,
"children": []
}]
}, {
"value": 2,
"children": []
}]
};
function getHighestValue(obj) {
var res = obj.value;
for(var i in obj.children) {
res = Math.max(res, getHighestValue(obj.children[i]));
}
return res;
}
alert(getHighestValue(baseObject));