> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/array/flattendepth.md).

# \_.flattenDepth(减少depth层嵌套)

**语法：**

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

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L7369)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.flattendepth)

**描述：**

根据`depth`递归减少`array`的嵌套层级

**开始版本：**&#x34;.4.0

**参数：**

* `array (Array)`: 需要减少嵌套层级的数组。
* `[depth=1] (number)`:最多减少的嵌套层级数。

**返回值：**

* `array (Array)`: 返回减少嵌套层级后的新数组。

**例子：**

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

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

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