0

I'm trying to write a code about GTFS with node-fetch. When I use the promise, It can return values but when I try to add them into an array for information filtering purposes. The system returned undefined values. What can I do with this situation?

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);

Here are the return values:

[ undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined,
  undefined ]
NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Sen Cai
  • 1
  • 3
  • IN addition, I have the value returned from the function by when I try to access the array of objects. The system said the value 'info' is undefined. – Sen Cai Aug 08 '18 at 13:57
  • Here are the result of function. – Sen Cai Aug 08 '18 at 13:57
  • { schedule: { '627': { N: [ { routeId: '6', delay: null, arrivalTime: 1533738510, departureTime: 1533738510 } ], S: [ { routeId: '6', delay: null, arrivalTime: 1533739230, departureTime: 1533739230 } ] } }, updatedOn: 1533735302 } – Sen Cai Aug 08 '18 at 14:00

0 Answers0