JSFiddle - React, Tailwind, and code Playground
JavaScript
var menuElements = [
{
"key": "siteSettings",
"title": "Настройки сайта",
"children": [
{
"key": "site_slider",
"title": "Слайдер",
"children": null,
"block": "slides"
}
],
"block": null
},
{
"key": "shopSettings",
"title": "Настройки магазина",
"children": [
{
"key": "product_category",
"title": "Категории товаров",
"children": null,
"block": "product_category"
},
{
"key": "site_configuration",
"title": "Конфигурация сайта",
"children": null,
"block": "site_configuration",
"type": "single"
}
],
"block": null
}
]
let result = []
menuElements.map((item) => {
for (var i = 0; i < item.children.length; i++) {
let obj = {
key: item.key,
title: item.title,
children: item.children[i].children ? item.children : []
};
if (item.children[i].type === 'single' || item.type === 'single') {
obj.type = item.type;
}
result.push (obj);
}
});
console.log('result', result)
return result