array-flat

0.0.3 • Public • Published

Array-Flat

Simple array flattening library since I couldn't find one on npm that would only flatten N levels :/

Installation

npm install --save array-flat

Usage

flattens any array or array-like object:

> var flatten = require('array-flat');
> flatten([1, 2, [3, 4, [5, 6, 0, 7]]])
[ 1, 2, 3, 4, 5, 6, 0, 7 ]

It takes an optional 2nd param which is the # of levels to flatten

> flatten([1, 2, [3, 4, [5, 6, 0, 7]]], 1)
[ 1, 2, 3, 4, [ 5, 6, 0, 7 ] ]

.compact (or flatten(ary, depth, removeFalsey)) removes all falsey values from the array at the same time (up to the level flattened):

> var compact = require('array-flat').compact;
> compact([1,2,[3, 4, [5, 6, 0, 7]]])
[ 1, 2, 3, 4, 5, 6, 7 ]

Package Sidebar

Install

npm i array-flat

Weekly Downloads

0

Version

0.0.3

License

Unlicense

Last publish

Collaborators

  • zyklus