ts-flatten-array
Version:
Array Flatten with Typescript
38 lines (24 loc) • 877 B
Markdown
Flattens nested arrays into one single array.
In your roject, run:
```shell
$ npm install ts-flatten-array --save-dev
```
Include the function:
```typescript
import { flattenArray } from 'ts-flatten-array';
```
Flattens an array without type declration:
```typescript
flattenArray([1, [2, 3, [4, 5], 6, [7]]]); // => [1, 2, 3, 4, 5, 6, 7]
```
Include the type:
```typescript
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"];
```