JSFiddle - React, Tailwind, and code Playground

by dzenkovich

JavaScript

//flatten array of arrays of arrays :)

var source = [[0, [1]], [2, [3, 4]], [5, [6, [7, 8]]]];

function isArray(object) {
	return Object.prototype.toString.call( object ) === '[object Array]'
}

function flatten(source, destination){
	if (isArray(source)) {
  	return source.reduce(function(destination, item) {
    	return destination.concat(flatten(item, destination))
    }, [])
  }
	return source;
}

console.log(flatten(source, []));