@extra-array/flatten

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

Usage no npm install needed!

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

README

Flattens nested array to given depth.

This is part of package extra-array.

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