[Solved] Generate Tree from flat Array javascript
You could use the level property for indicating the nested position in a helper array. Then iterate the data and build children nodes if necessary. function getTree(array) { var levels = [{}]; array.forEach(function (a) { levels.length = a.level; levels[a.level – 1].nodes = levels[a.level – 1].nodes || []; levels[a.level – 1].nodes.push(a); levels[a.level] = a; }); return … Read more