1.1.0 • Published 5 years ago

arraylist-to-tree v1.1.0

Weekly downloads
7
License
MIT
Repository
-
Last release
5 years ago

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