I have to use the directory array in javascript to display directory for the web. But I don't know how to put the condition in this case.
const directory = [
{ type: 'file', name: 'file1.txt' },
{ type: 'file', name: 'file2.txt' },
{
type: 'directory',
name: 'HTML Files',
files: [
{ type: 'file', name: 'file1.html' },
{ type: 'file', name: 'file2.html' }
]
},
{ type: 'file', name: 'file3.txt' },
{
type: 'directory',
name: 'JavaScript Files',
files: [
{ type: 'file', name: 'file1.js' },
{ type: 'file', name: 'file2.js' },
{ type: 'file', name: 'file3.js' }
]
}
];
The part I am writing but I don't know how to check the condition since all types all file:
var File = '\0';
if ()
directory.forEach(eachFile => {
File = File + `<li>${eachFile}</li>`;
});
and this is my HTML file.
<div id="directories">
<header>
<title>File Directories</title>
</header>
<body>
<h2>Directories</h2>
<ul id = "displayDirectories"></ul>
</body>
</div>
And this is how output should be:
