-
Notifications
You must be signed in to change notification settings - Fork 5
flat
Subhajit Sahu edited this page May 19, 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 ] ]