开发者社区> 问答> 正文

我需要创建一个JS代码段,该代码段将遍历数组并在下面打印出结果

var arr = [ { name: 'Folder 1', type: 'folder', size: '34kb', children: [ { name: 'Folder 11', type: 'folder', size: '14kb', children: [ { name: 'Folder 111', type: 'folder', size: '14kb', children: [] }, { name: 'Folder 112', type: 'folder', size: '14kb', children: [] }, { name: 'file113.png', type: 'file', size: '2kb' } ] }, { name: 'Folder 12', type: 'folder', size: '14kb', children: [] }, { name: 'Folder 13', type: 'folder', size: '14kb', children: [ { name: 'Folder 131', type: 'folder', size: '14kb', children: [] }, { name: 'Folder 132', type: 'folder', size: '14kb', children: [] }, { name: 'file133.png', type: 'file', size: '2kb' } ] } ] }, { name: 'Folder 2', type: 'folder', size: '34kb', children: [ { name: 'file21.png', type: 'file', size: '2kb' }, { name: 'file22.png', type: 'file', size: '2kb' }, { name: 'file23.png', type: 'file', size: '2kb' }, { name: 'file24.png', type: 'file', size: '2kb' } ] } ] 我需要打印出:

/** Display result:

-Folder 1 (34kb) --Folder 11 (14kb) ---Folder 111 (14kb) ---Folder 112 (14kb) -->file113.png --Folder 12 (14kb) --Folder 13 (14kb) ---Folder 131 (14kb) ---Folder 132 (14kb) -->file133.png (14kb) -folder 2 (34kb) ->file21.png (14kb) ->file22.png (14kb) ->file23.png (14kb) ->file24.png (14kb) */

展开
收起
被纵养的懒猫 2019-10-08 17:33:04 338 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
JavaScript异步编程 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载