Javascript flatten on property

Date: 2021-06-18
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function flatten(list: any[]) {
const result = [];
function internalFlatten(list: any[]) {
list.forEach(item => {
result.push(item);
internalFlatten(item.children);
});
}
internalFlatten(list);
return result;
}
flatten([{ children: [{}, {}] }]);
function flatten(list: any[]) { const result = []; function internalFlatten(list: any[]) { list.forEach(item => { result.push(item); internalFlatten(item.children); }); } internalFlatten(list); return result; } flatten([{ children: [{}, {}] }]);
function flatten(list: any[]) {
    const result = [];
    function internalFlatten(list: any[]) {
        list.forEach(item => {
            result.push(item);
            internalFlatten(item.children);
        });
    }
    internalFlatten(list);
    return result;
}
flatten([{ children: [{}, {}] }]);
51230cookie-checkJavascript flatten on property
0 of 2000 max characters.