-
Anonymous
Как добавить все дочерние массивы в один массив?
Сообщение
Anonymous »
У меня есть такой файл констант:
Код: Выделить всё
const files = [{
id: 232141332,
title: "Работа",
type: "FOALDER",
opened: true,
level: 0,
fatherId: null,
children: [{
id: 734573086,
title: "MA5600",
type: "FOALDER",
opened: true,
level: 1,
fatherId: 232141332,
children: [{
id: 867407333,
title: "удалить плату",
type: "FILE",
opened: false,
level: 2,
fatherId: 734573086,
children: []
},
{
id: 110345245,
title: "добавить плату",
type: "FILE",
opened: false,
level: 2,
fatherId: 734573086,
children: []
}
]
},
{
id: 222225454,
title: "C300M",
type: "FOALDER",
opened: true,
level: 1,
fatherId: 232141332,
children: [{
id: 333334256,
title: "добавить опцию TR-82",
type: "FILE",
opened: false,
level: 2,
fatherId: 222225454,
children: []
}]
}
]
},
{
id: 23232,
title: "Прога",
type: "FOALDER",
opened: true,
level: 0,
fatherId: null,
children: [{
id: 2323242,
title: "React",
type: "FOALDER",
opened: true,
level: 1,
fatherId: 1224232,
children: [{
id: 45674734,
title: "добавить компонент",
type: "FILE",
opened: false,
level: 2,
fatherId: 734573086,
children: []
},
{
id: 5368876,
title: "удалить компонент",
type: "FILE",
opened: false,
level: 2,
fatherId: 734573086,
children: []
}
]
},
{
id: 258089,
title: "SQL",
type: "FOALDER",
opened: true,
level: 1,
fatherId: 232141332,
children: [{
id: 1112312,
title: "посмотреть количество по условию",
type: "FILE",
opened: false,
level: 2,
fatherId: 222225454,
children: []
}]
}
]
}
]
Как создать массив, который будет состоять из всех дочерних элементов одного элемента файлов? Вот так:
Код: Выделить всё
[{"MA5600"}, {удалить плату}, {добавить плату}, {C300M}, {добавить опцию TR-82}].
Это массив всех дочерних элементов объекта с заголовком Работа, но мне нужны не только имена, а целые файлы.
Подробнее здесь:
https://stackoverflow.com/questions/793 ... -one-array
1737460520
Anonymous
У меня есть такой файл констант:
[code]const files = [{
id: 232141332,
title: "Работа",
type: "FOALDER",
opened: true,
level: 0,
fatherId: null,
children: [{
id: 734573086,
title: "MA5600",
type: "FOALDER",
opened: true,
level: 1,
fatherId: 232141332,
children: [{
id: 867407333,
title: "удалить плату",
type: "FILE",
opened: false,
level: 2,
fatherId: 734573086,
children: []
},
{
id: 110345245,
title: "добавить плату",
type: "FILE",
opened: false,
level: 2,
fatherId: 734573086,
children: []
}
]
},
{
id: 222225454,
title: "C300M",
type: "FOALDER",
opened: true,
level: 1,
fatherId: 232141332,
children: [{
id: 333334256,
title: "добавить опцию TR-82",
type: "FILE",
opened: false,
level: 2,
fatherId: 222225454,
children: []
}]
}
]
},
{
id: 23232,
title: "Прога",
type: "FOALDER",
opened: true,
level: 0,
fatherId: null,
children: [{
id: 2323242,
title: "React",
type: "FOALDER",
opened: true,
level: 1,
fatherId: 1224232,
children: [{
id: 45674734,
title: "добавить компонент",
type: "FILE",
opened: false,
level: 2,
fatherId: 734573086,
children: []
},
{
id: 5368876,
title: "удалить компонент",
type: "FILE",
opened: false,
level: 2,
fatherId: 734573086,
children: []
}
]
},
{
id: 258089,
title: "SQL",
type: "FOALDER",
opened: true,
level: 1,
fatherId: 232141332,
children: [{
id: 1112312,
title: "посмотреть количество по условию",
type: "FILE",
opened: false,
level: 2,
fatherId: 222225454,
children: []
}]
}
]
}
]
[/code]
Как создать массив, который будет состоять из всех дочерних элементов одного элемента файлов? Вот так:
[code][{"MA5600"}, {удалить плату}, {добавить плату}, {C300M}, {добавить опцию TR-82}].
[/code]
Это массив всех дочерних элементов объекта с заголовком Работа, но мне нужны не только имена, а целые файлы.
Подробнее здесь: [url]https://stackoverflow.com/questions/79374259/how-to-add-all-child-arrays-to-one-array[/url]