@extra-array/flatten.min

Flattens nested array to given depth. > This is part of package [extra-array].

Usage no npm install needed!

<script type="module">
  import extraArrayFlattenMin from 'https://cdn.skypack.dev/@extra-array/flatten.min';
</script>

README

Flattens nested array to given depth.

This is part of package extra-array.

This is browserified, minified version of @extra-array/flatten.
It is exported as global variable array_flatten.
CDN: unpkg, jsDelivr.

array.flatten(x, [dep]);
// x:   a nested array
// dep: maximum depth (-1)
// --> flattened
const array = require('extra-array');

var x = [[1, 2], [3, [4, [5]]]];
array.flatten(x);
// [1, 2, 3, 4, 5]

array.flatten(x, 1);
// [1, 2, 3, [4, [5]]]

array.flatten(x, 2);
// [1, 2, 3, 4, [5]]

references