UNPKG

arraylist-to-tree

Version:

array of list to tree

56 lines (44 loc) 849 B
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`