JSFiddle - React, Tailwind, and code Playground
by brigand
JavaScript
Array.prototype.flat = function(depth) {
depth = Math.floor(depth) || 1;
var flattend = [];
!(function flat(array, depth) {
array.forEach(function(el) {
if (Array.isArray(el) && depth > 0) {
flat(el, depth - 1);
} else flattend.push(el);
});
})(this, depth);
return flattend;
};
console.log([[1], [[3], 2]].flat(1))