arraylist-to-tree

1.1.0 • Public • Published

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

Package Sidebar

Install

npm i arraylist-to-tree

Weekly Downloads

4

Version

1.1.0

License

MIT

Unpacked Size

4.61 kB

Total Files

5

Last publish

Collaborators

  • ganz