arraylist-to-tree
v1.1.0
Published
array of list to tree
Downloads
6
Maintainers
Readme
arraylist-to-tree
A small library that converts Array of list to tree view
Installation
npm install arraylist-to-tree
Usage
const tree = require('arraylistTotree');
const list = [{
id: 1,
parentInt: 0
}, {
id: 2,
parentInt: 1
}, {
id: 3,
parentInt: 1
}, {
id: 4,
parentInt: 2
}, {
id: 5,
parentInt: 2
}];
Result
[{
"id": 1,
"parentInt": 0,
"children": [
{
"id": 2,
"parentInt": 1,
"children": [
{
"id": 4,
"parentInt": 2
}, {
"id": 5,
"parentInt": 2
}
]
}]
}]
Tests
npm test