tree-flatten
Version:
Flatten nested tree objects to array
46 lines (38 loc) • 1.34 kB
Markdown
[](https://nodei.co/npm/tree-flatten/)
[](https://travis-ci.org/cantidio/node-tree-flatten)
[](https://codeclimate.com/github/cantidio/node-tree-flatten)
[](https://codeclimate.com/github/cantidio/node-tree-flatten/coverage)
[](https://david-dm.org/cantidio/node-tree-flatten)
[](https://david-dm.org/cantidio/node-tree-flatten#info=devDependencies)
# Tree Flatten
> Flatten nested tree objects to array
## Install
```
npm install --save tree-flatten
```
## Usage
```js
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' },
]
*/
```
### License
MIT