function flat(arr = [1,2,3,[4,5,[6,7]]],deep = 0){ if(deep <= 0){ return arr } if(deep == Number.Infinity){ while(arr.some(Array.isArray)){ arr = [].concat(...arr) } return arr } while(arr.some(Array.isArray) && deep > 0){ arr = [].concat(...arr) deep-- } return arr }
原文:https://www.cnblogs.com/zhenjianyu/p/13341974.html