Recursively flattens an array of nested arrays into a single-level array.
The type of elements in the array.
The array to flatten, which may contain nested arrays.
A new array with all nested elements flattened into a single level.
// ES Moduleimport { flattenArray } from '@bnidev/js-utils'// CommonJSconst { flattenArray } = require('@bnidev/js-utils') Copy
// ES Moduleimport { flattenArray } from '@bnidev/js-utils'// CommonJSconst { flattenArray } = require('@bnidev/js-utils')
const nestedArray = [1, [2, 3], [[4]], 5]const flatArray = flattenArray(nestedArray)console.log(flatArray) // Output: [1, 2, 3, 4, 5] Copy
const nestedArray = [1, [2, 3], [[4]], 5]const flatArray = flattenArray(nestedArray)console.log(flatArray) // Output: [1, 2, 3, 4, 5]
Recursively flattens an array of nested arrays into a single-level array.