Recursively flatten `array` up to `depth` times.
const array = [1, [2, [3, [4]], 5]]
flattenDepth(array, 1)
// => [1, 2, [3, [4]], 5]
flattenDepth(array, 2)
// => [1, 2, 3, [4], 5]
| Name | Type | Attribute | Description |
|---|---|---|---|
| array | The array to flatten. | ||
| depth | The maximum recursion depth. |
{
"comment": "/**\r\n * Recursively flatten `array` up to `depth` times.\r\n *\r\n * @since 4.4.0\r\n * @category Array\r\n * @param {Array} array The array to flatten.\r\n * @param {number} [depth=1] The maximum recursion depth.\r\n * @returns {Array} Returns the new flattened array.\r\n * @see flatMap, flatMapDeep, flatMapDepth, flattenDeep\r\n * @example\r\n *\r\n * const array = [1, [2, [3, [4]], 5]]\r\n *\r\n * flattenDepth(array, 1)\r\n * // => [1, 2, [3, [4]], 5]\r\n *\r\n * flattenDepth(array, 2)\r\n * // => [1, 2, 3, [4], 5]\r\n */",
"meta": {
"range": [
554,
763
],
"filename": "flattenDepth.js",
"lineno": 22,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100002703",
"name": "flattenDepth",
"type": "FunctionDeclaration",
"paramnames": [
"array",
"depth"
]
},
"vars": {
"length": "flattenDepth~length",
"depth": "flattenDepth~depth"
}
},
"description": "Recursively flatten `array` up to `depth` times.",
"since": "4.4.0",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Array",
"value": "Array"
}
],
"params": [
{
"type": {
"names": [
"Array"
]
},
"description": "The array to flatten.",
"name": "array"
},
{
"type": {
"names": [
"number"
]
},
"optional": true,
"defaultvalue": 1,
"description": "The maximum recursion depth.",
"name": "depth"
}
],
"returns": [
{
"type": {
"names": [
"Array"
]
},
"description": "Returns the new flattened array."
}
],
"see": [
"flatMap, flatMapDeep, flatMapDepth, flattenDeep"
],
"examples": [
"const array = [1, [2, [3, [4]], 5]]\r\rflattenDepth(array, 1)\r// => [1, 2, [3, [4]], 5]\r\rflattenDepth(array, 2)\r// => [1, 2, 3, [4], 5]"
],
"name": "flattenDepth",
"longname": "flattenDepth",
"kind": "function",
"scope": "global",
"___id": "T000002R000292",
"___s": true,
"filepath": "flattenDepth.js"
}