我正在尝试使用node-fetch编写有关GTFS的代码。当我使用promise时,它可以返回值,但是当我尝试将它们添加到数组中以进行信息过滤时。系统返回了未定义的值。在这种情况下我该怎么办?
function getStopInfo(StopId){
mta.schedule(StopId).then(function (result) {
console.dir(result, {depth:null, colors:true});});
}
global.info = getStopInfo('627');
global.a = Array(20).fill(info);
console.log(global.a);
以下是返回值:
[ undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined ]