Flattens
array
a single or multiple level deep.
npm install -S @jswork/next-flat
import '@jswork/next-flat';
const res = nx.flat([[1, 2, 3], [4, 5]]);
// [1, 2, 3, 4, 5]
function flattenArrayOfArrays(a, r) {
if (!r) { r = [] }
for (var i = 0; i < a.length; i++) {
if (a[i].constructor == Array) {
r.concat(flattenArrayOfArrays(a[i], r));
} else {
r.push(a[i]);
}
}
return r;
}
Code released under the MIT license.