Recursive function Last updated: 31. Jan 2023
Example showing a recursive function (a function calling itself).
Example
Data
{
"folders" :
[
{
"name" : "Folder 1",
"folders" :
[
{
"name" : "Folder 1.1",
"folders" : []
}
]
}
]
}
Code
Option 1 (##JS):
#for(let folder of folders) {#
Folder: #folder.name#
#for(let folder of folder.folders) {#{{current}}#}#
#}#
Option 2 (Pure JS):
#{
function showFolders(folders) {
for(let folder of folders) {
write("Folder: " + folder.name + "\n");
//showFolders(folder.folders);
}
}
showFolders(folders);
}#
Output
Option 1 (#JS):
Folder: Folder 1
Folder: Folder 1.1
Option 2 (Pure JS):
Folder: Folder 1