У меня есть массив вложенных объектов, и я хотел бы немного его упростить и преобразовать в объект с парами ключ-значение, поэтому результат будет следующим:
Простой объект:
{Groceries: {
'Organic eggs': null,
Fruits: {
Apple: null,
Berries: {
Blueberry: null,
Raspberry: null
}
}
}}
Массив вложенных объектов:
const tree = [{
"id": 1,
"name": "Groceries",
"parentId": null,
"children": [{
"id": 3,
"name": "Organic eggs",
"parentId": 1,
"children": []
}, {
"id": 5,
"name": "Fruits",
"parentId": 1,
"children": [{
"id": 6,
"name": "Apple",
"parentId": 5,
"children": []
},{
"id": 7,
"name": "Berries",
"parentId": 5,
"children": [{
"id": 8,
"name": "Blueberry",
"parentId": 7,
"children": []
},{
"id": 9,
"name": "Raspberry",
"parentId": 7,
"children": []
}]
}]
}]
}]