JSFiddle - React, Tailwind, and code Playground

by 3gwebtrain

JavaScript

function flat(array) {
    var result = [];
    array.forEach(function (a) {
        result.push(a);
        if (Array.isArray(a.children)) {
            result = result.concat(flat(a.children));
        }
    });
    return result;
}


    result = flat(data);
    
    console.log(result)