用递归的方法扁平化数组

51 阅读1分钟
// 扁平化数组
export function flatten(arr) {
  return arr.reduce((res, next) => {
    return res.concat(Array.isArray(next) ? flatten(next) : next)
  }, [])
}