Is there a way to transform the array structure that represents parent-relation into a 2D array format?
const array = [{id: 1, parentId: 2}, {parentId: null, id: 2}];
The goal is to create a new array where the first element of each nested array is the parent with no parentId specified, and the last element is always the child or leaf element.
For example:
const array_2 = [
[{ id: 1, parentId: null}, { id:2, parentId: 1 }, { id: 3, parentId: 2}], [...], [...]
]