我正在尝试使用 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 ]