Flatten nested tree objects to array
npm install --save tree-flatten
const flatten = require('tree-flatten');
const tree = {
name: 'root-1',
children: [{
name: 'root-1-1'
}, {
name: 'root-1-2',
children:[{
name: 'root-1-2-1'
}]
}]
};
flatten(tree, 'children')
/* =>
[
{ name: 'root-1' },
{ name: 'root-1-1' },
{ name: 'root-1-2' },
{ name: 'root-1-2-1' },
]
*/
MIT