0
点赞
收藏
分享

微信扫一扫

数组扁平化处理

数组扁平化

//扁平化
function flat(arr) {
    //验证arr数组中,还有没有深层数组[1,2,[3,4]]
    const isDeep = arr.some(item => item instanceof Array)
    if(!isDeep) {
        return arr
    }

    const res = Array.prototype.concat.apply([], arr)
    return flat(res)//递归拍平
}
举报

相关推荐

0 条评论