# flat-util

> Flatten a nested array.

Latest version **1.1.11** (published 2025-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install flat-util
pnpm add flat-util
yarn add flat-util
bun add flat-util
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.11 |
| Published | 2025-02-01 |
| First published | 2020-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jonathan Kemp |
| Maintainers | jonkemp |
| Keywords | array, flat, flatten, nested, utility, util |

## Links

- npm: https://www.npmjs.com/package/flat-util
- Repository: https://github.com/jonkemp/flat-util
- Homepage: https://github.com/jonkemp/flat-util#readme
- Issues: https://github.com/jonkemp/flat-util/issues
- npm.io page: https://npm.io/package/flat-util

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.1.11 (latest) — 2025-02-01
- 1.1.0-0 (alpha) — 2020-02-20
- 1.1.10 — 2025-01-31
- 1.1.9 — 2022-03-22
- 1.1.8 — 2021-11-09
- 1.1.7 — 2020-10-30
- 1.1.6 — 2020-10-22
- 1.1.5 — 2020-03-29
- 1.1.4 — 2020-03-28
- 1.1.3 — 2020-03-25
- 1.1.2 — 2020-03-25
- 1.1.1 — 2020-02-20
- 1.1.0 — 2020-02-20
- 1.0.5 — 2020-02-09
- 1.0.4 — 2020-01-29
- … 4 more at https://npm.io/package/flat-util/versions

## README

# flat-util ![Build Status](https://github.com/jonkemp/flat-util/actions/workflows/main.yml/badge.svg?branch=master)

> Flatten a nested array.

The nesting can be to any depth. If you pass shallow, the array will only be flattened one level. 

## Features

- Small utility to flatten nested arrays.
- Free of TypeScript. 😄


## Install

Install with [npm](https://npmjs.org/package/flat-util)

```
$ npm install flat-util
```

Or [unpkg](https://unpkg.com/flat-util/)

```
<script src="https://unpkg.com/flat-util@1.1.9/umd/index.js" />
```

Check out the unit tests on [CodePen](https://codepen.io/jonkemp/full/YzPBmwz).

## Usage

```js
const flatten = require('flat-util');

flatten([1, 2, [3, 4]]);
//=> [1, 2, 3, 4]

flatten([1, [2], [3, [[4]]]]);
//=> [1, 2, 3, 4];

flatten([1, [2], [3, [[4]]]], true);
//=> [1, 2, 3, [[4]]];
```

---
| **Like us a lot?** Help others know why you like us! **Review this package on [pkgreview.dev](https://pkgreview.dev/npm/flat-util)** | ➡   | [![Review us on pkgreview.dev](https://i.ibb.co/McjVMfb/pkgreview-dev.jpg)](https://pkgreview.dev/npm/flat-util) |
| ----------------------------------------------------------------------------------------------------------------------------------------- | --- | --------------------------------------------------------------------------------------------------------------------- |

## API

### flatten(input, shallow)

#### input

Type: `array`  
Default: `none`

The array to flatten.

#### shallow

Type: `boolean`  
Default: `false`

Whether or not to flatten the array only one level.

## License

MIT

---
_Source: https://npm.io/package/flat-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
