@extra-array/flatten
v2.3.10
Published
Flattens nested array to given depth.
Downloads
97
Maintainers
Keywords
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]]