My database is structured as an array of objects with the following format;
array = [ {"name": "a", "id": "1", "parentId": NULL},
{"name": "b", "id": "2", "parentId": "1"},
{"name": "c", "id": "3", "parentId": "1"},
{"name": "d", "id": "4", "parentId": "1"},
{"name": "e", "id": "5", "parentId": "2"},
{"name": "f", "id": "6", "parentId": "3"},
{"name": "g", "id": "7", "parentId": "3"},
{"name": "h", "id": "8", "parentId": "4"},
{"name": "j", "id": "9", "parentId": "4"}]
I am aiming to transform this array into a tree structure as follows;
{
a: {
b: {
e: {}
},
c: {
f: {},
g: {}
},
d: {
h: {},
j: {}
}
}
}