🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

flat-util

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flat-util

Flatten a nested array.

latest
Source
npmnpm
Version
1.1.11
Version published
Weekly downloads
317K
-9.95%
Maintainers
1
Weekly downloads
 
Created
Source

flat-util Build Status

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

$ npm install flat-util

Or unpkg

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

Check out the unit tests on CodePen.

Usage

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.devReview us on pkgreview.dev

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

Keywords

array

FAQs

Package last updated on 01 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts