if (args[0] === "help") {
var help_array = [];
fs.readdir('./commands/', (err, files) => {
files.forEach((response) => {
var commandFile = require('./commands/' + response);
help_array.push(commandFile.getHelp());
console.log(help_array); // <----- array with elements
});
});
console.log(help_array); // <----------- empty array []
return;
}
为什么会这样?我怎么能解决这个问题?它与异步函数有关吗?