@nevware21/ts-utils
    Preparing search index...

    Function arrFlatten

    • Function

      The arrFlatten() method returns a new array with all sub-array elements flattened up to the specified depth (default 1).

      Type Parameters

      • T

        Identifies the base type of array elements

      Parameters

      • theArray: ArrayLike<any[] | T>

        The array or array-like object to flatten

      • Optionaldepth: number

        The flattening depth, defaults to 1. Use Infinity for complete flattening

      Returns any[]

      A new flattened array

      0.14.0

      arrFlatten([1, [2, 3], [4, [5, 6]]]);           // [1, 2, 3, 4, [5, 6]]
      arrFlatten([1, [2, 3], [4, [5, 6]]], 2); // [1, 2, 3, 4, 5, 6]
      arrFlatten([1, [2, 3], [4, [5, 6]]], Infinity); // [1, 2, 3, 4, 5, 6]
      arrFlatten([1, 2, 3]); // [1, 2, 3]
      arrFlatten([]); // []

      // With array-like objects
      arrFlatten({ length: 2, 0: 1, 1: [2, 3] }); // [1, 2, 3]