I have a nested array of objects which I need to convert to one dimensional Array of objects. In the final Array the 'childrens' is not required.
"Edit": I also need to concatenate the path values of childrens
Original Array
const data = [
{
title: "Dashboard",
icon: "Dashboard",
page:"<Dashboard./>",
path: "dashboard"
},
{
title: "Management",
icon: "Management",
page:"<Management/>",
path: "manage",
childrens:[
{
title: "Assets",
icon: "Dot",
page:"<Assetshome/>",
path: "assets",
childrens:[
{
title: "MyAssets",
icon: "Dot",
page:"<Myassets/>",
path: "myassets"
},
{
title: "AddAssets",
icon: "Dot",
page:"<Addassets/>",
path: "addassets"
}
]
},
{
title: "Users",
icon: "Dot",
page: "<Users/>"
path: "users"
},
{
title: "Office",
icon: "Dot",
page:"<Office/>"
path: "office"
}
]
},
{
title: "Reports",
icon: "Reports",
page:"<Reports/>"
path: "reports"
}
]
Required flattened Array having path values of childrens concatenated.
const newdata = [
{
title: "Dashboard",
icon: "Dashboard",
page:"<Dashboard/>",
path: "dashboard"
},
{
title: "Management",
icon: "Management",
page:"<Management/>",
path: "manage"
},
{
title: "Assets",
icon: "Dot",
page:"<Assetshome/>",
path: "manage/assets"
},
{
title: "MyAssets",
icon: "Dot",
page:"<Myassets/>",
path: "manage/assets/myassets"
},
{
title: "AddAssets",
icon: "Dot",
page:"<Addassets/>",
path: "manage/assets/addassets"
},
{
title: "Users",
icon: "Dot",
page: "<Users/>"
path: "users"
},
{
title: "Office",
icon: "Dot",
page:"<Office/>"
path: "office"
},
{
title: "Reports",
icon: "Reports",
page: "<Reports/>"
path: "reports"
}
]
What is the best way to do this in javascript.