Skip to content
wolfram77 edited this page Apr 13, 2020 · 20 revisions

Flattens nested array to given depth. [:running:] [:vhs:] [:package:] [:moon:]

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

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

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

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

references

Clone this wiki locally