Flattens nested arrays into one single array.
In your roject, run:
$ npm install ts-flatten-array --save-dev
Include the function:
import { flattenArray } from 'ts-flatten-array';
Flattens an array without type declration:
flattenArray([1, [2, 3, [4, 5], 6, [7]]]); // => [1, 2, 3, 4, 5, 6, 7]
Include the type:
import { NestedArray } from 'ts-flatten-array';
let inputArrayNumber: NestedArray<number> = [1, [2, [3, 3, [6, 3, 1, 2, 4]]], 4];
let inputArrayString: NestedArray<string> = ["apple", ["pear", ["cherry", "berry", ]], "grape"];
let inputArrayNumberAndString: NestedArray<string | number> = ["apple", ["pear", ["cherry", [3, 3, [6, 3, 1, 2, 4]], "berry", ]], "grape"];