Skip to content

flattenDepth

js
_.flattenDepth(array, [depth=1])

递归地将 array 展平至 depth 次。

¥Recursively flatten array up to depth times.

新增于

¥Since

4.4.0

参数

¥Arguments

  1. array (数组):要展平的数组。

    ¥array (Array): The array to flatten.

  2. [depth=1] (数值):最大字符串长度。

    ¥[depth=1] (number): The maximum recursion depth.

返回

¥Returns

(数组):返回新的扁平化数组。

¥(Array): Returns the new flattened array.

示例

¥Example

js
var array = [1, [2, [3, [4]], 5]];

_.flattenDepth(array, 1);
// => [1, 2, [3, [4]], 5]

_.flattenDepth(array, 2);
// => [1, 2, 3, [4], 5]

Lodash v4.17 中文网 - 粤ICP备13048890号