Skip to content
Subhajit Sahu edited this page Mar 22, 2020 · 20 revisions

Flattens nested array to given depth.

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