Here is the array I'm working with:
Array (7812)
0 {foldername: "", amount_of_files: 12, children: 86}
1 {foldername: "/pm", amount_of_files: 3, children: 7}
2 {foldername: "/pm/css", amount_of_files: 1, children: 0}
3 {foldername: "/pm/js", amount_of_files: 1, children: 0}
4 {foldername: "/stohg", amount_of_files: 1, children: 2}
5 {foldername: "/stohg/de", amount_of_files: 6, children: 1}
6 {foldername: "/stohg/de/pictures", amount_of_files: 21, children: 1}
...
I am aiming to calculate the total number of files at the top level:
1 {foldername: "/pm", all_files: 5}
2 {foldername: "/stohg", all_files: 28}
...
This snippet looks like a step in the right direction:
array.filter(e => {
const folders = e.foldername.split("/");
if (folders.length === 1) {
//maybe something with folders.reduce(); ?
}
})