let navigation = [{
id: 1,
subitems: [{
id: 2,
subitems: [{
id: 3,
subitems: [],
parent: 2
},
{
id: 4,
subitems: [],
parent: 2
}
],
parent: 1
},
{
id: 5,
subitems: [],
parent: 1
}
]
},
{
id: 6,
subitems: []
}
];
function flatten(array) {
return [].concat(...array.map(item => [].concat(item, ...flatten(item.subitems))))
}
navigation = flatten(navigation)
console.log("navigation", navigation);
let arr = [{
id: 1,
text: "Folder1",
iconCls: "icon-save",
children: [{
text: "File1",
checked: true
}, {
text: "Books",
state: "open",
attributes: {
url: "/demo/book/abc",
price: 100
},
children: [{
text: "PhotoShop",
checked: true
}, {
id: 8,
text: "Sub Bookds",
state: "closed"
}]
}]
}, {
text: "Languages",
state: "closed",
children: [{
text: "Java"
}, {
text: "C#"
}]
}]
let result = []
function getId(arr) {
arr.forEach(v => {
result.push(v);
if (v.children instanceof Array) {
getId(v.children)
}
});
}
getId(arr)
console.log(result);