用法
flatten 函数用于将嵌套数组展平到指定深度。
import { flatten } from '@movk/core'
const nested = [1, [2, 3], [4, [5, 6]]]
const flat1 = flatten(nested)
console.log(flat1) // [1, 2, 3, 4, [5, 6]]
const flat2 = flatten(nested, 2)
console.log(flat2) // [1, 2, 3, 4, 5, 6]
API
flatten<T>(arr, depth?)
将嵌套数组展平到指定深度。
参数
arr
T[] required
待扁平化的数组。
depth
number
扁平化深度,默认为
1。返回值
返回值
any[]
扁平化后的数组。
Changelog
No recent changes