I wanted to get a array of objects in a flat sturcture for the parent it’s child and it’s grand child and it’s great grandchild and so on

I have an array of objects like below
[{Portfolio:”AMBAL”,
Level:1,
Immediate Parent:””},
{Portfolio:”AMBAL-PI”,
Level:2,
Immediate Parent:”AMBAL”},
{Portfolio:”AMBAL-FI”,
Level:2,
Immediate Parent:”AMBAL”},

{Portfolio:”2213AMBAL”,
Level:3,
Immediate Parent:”AMBAL-FI”},
{Portfolio:”2132AMBAL”,
Level:3,
Immediate Parent:”AMBAL-PI”}….]

I have just gave example of level 3 but it could may have more also….

Expected o/p

[{Portfolio:”AMBAL”,
Level:1,
Immediate Parent:””},

{Portfolio:”AMBAL-FI”,
Level:2,
Immediate Parent:”AMBAL”},

{Portfolio:”2213AMBAL”,
Level:3,
Immediate Parent:”AMBAL-FI”},

{Portfolio:”AMBAL-PI”,
Level:2,
Immediate Parent:”AMBAL”},

{Portfolio:”2132AMBAL”,
Level:3,
Immediate Parent:”AMBAL-PI”}

]
Return the above array of objects using javascript only