Flatten a multi-dimensional array in JavaScript.
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
benchmark Fix benchmarks (#8) Dec 20, 2016
.editorconfig add editorconfig May 9, 2015
.gitignore Initial commit. Mar 16, 2014
.travis.yml Add node.js versions for Travis-ci Sep 19, 2015
LICENSE Initial commit. Mar 16, 2014
README.md Add Greenkeeper badge 🌴 (#16) May 6, 2017
array-flatten.d.ts Fix the TypeScript definition for array re-use (#11) Jan 14, 2017
array-flatten.js
bower.json v2.1.1 Jan 14, 2017
package.json chore(package): update benchmarked to version 2.0.0 (#17) Sep 12, 2017
test.js Refactor API with type errors for DX Nov 16, 2015

README.md

Array Flatten

NPM version NPM downloads Build status Test coverage Greenkeeper badge

Flatten nested arrays.

Installation

npm install array-flatten --save

Usage

var flatten = require('array-flatten')

flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]

flatten.depth([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
//=> [1, 2, 3, [4, [5], 6], 7, 8, 9]

(function () {
  flatten.from(arguments) //=> [1, 2, 3]
})(1, [2, 3])

Methods

  • flatten(array) Flatten a nested array structure
  • flatten.from(arrayish) Flatten an array-like structure (E.g. arguments)
  • flatten.depth(array, depth) Flatten a nested array structure with a specific depth
  • flatten.fromDepth(arrayish, depth) Flatten an array-like structure with a specific depth

License

MIT