function getArrayDepth(arr) {
const depths = []
arr.forEach( ele => {
let depth = 0
if (Array.isArray(ele)) {
depth = getArrayDepth(ele)
}
depths.push(depth)
})
return 1 + max(depths)
}
function max(arr) {
return arr.reduce( (accu, curr) => {
if (curr > accu) return curr
return accu
})
}
来源:CSDN
作者:dreamjay1997
链接:https://blog.csdn.net/dreamjay1997/article/details/104253222