@bnidev/js-utils
    Preparing search index...

    Function flattenArray

    • Recursively flattens an array of nested arrays into a single-level array.

      Type Parameters

      • T

        The type of elements in the array.

      Parameters

      • arr: (T | T[])[]

        The array to flatten, which may contain nested arrays.

      Returns T[]

      A new array with all nested elements flattened into a single level.

      // ES Module
      import { flattenArray } from '@bnidev/js-utils'

      // CommonJS
      const { 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]