项目作者: jonkemp

项目描述 :
Small utility to flatten a nested array
高级语言: JavaScript
项目地址: git://github.com/jonkemp/flat-util.git
创建时间: 2020-01-22T03:53:09Z
项目社区:https://github.com/jonkemp/flat-util

开源协议:MIT License

下载


" class="reference-link">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

  1. $ npm install flat-util

Or unpkg

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

Check out the unit tests on CodePen.

Usage

  1. const flatten = require('flat-util');
  2. flatten([1, 2, [3, 4]]);
  3. //=> [1, 2, 3, 4]
  4. flatten([1, [2], [3, [[4]]]]);
  5. //=> [1, 2, 3, 4];
  6. flatten([1, [2], [3, [[4]]]], true);
  7. //=> [1, 2, 3, [[4]]];

Like us a lot? Help others know why you like us! Review this package on pkgreview.dev Review 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