Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

flatten-deep

v4.17.15arrow_drop_down
v4.17.15
v4.17.11
STATUS
Passing
DOWNLOADS
158
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
3 months ago
SIZE
N/A
Recursively flattens `array`.
2 contributors
Install flatten-deep as a package?
Copied
npm i @bit/lodash.lodash.flatten-deep
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
flattenDeep.js
24 Lines(7 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import baseFlatten from './.internal/baseFlatten.js'

/** Used as references for various `Number` constants. */
const INFINITY = 1 / 0

/**
 * Recursively flattens `array`.
 *
 * @since 3.0.0
 * @category Array
 * @param {Array} array The array to flatten.
 * @returns {Array} Returns the new flattened array.
 * @see flatMap, flatMapDeep, flatMapDepth, flatten, flattenDepth
 * @example
 *
 * flattenDeep([1, [2, [3, [4]], 5]])
 * // => [1, 2, 3, 4, 5]
 */
function flattenDeep(array) {
  const length = array == null ? 0 : array.length
  return length ? baseFlatten(array, INFINITY) : []
}

export default flattenDeep