-3

Can someone help me with this?

The array always return blank.

var x = [];
geocoder.geocode('29 champs elysée paris', function(err, res) {
x.push(res)
});
console.log(x);

/* The result( res ) of the function is a Array....

1 Answers1

-1

geocoder.geocode() runs asynchronously.

Is this more what you're looking for?

var x = [];
geocoder.geocode('29 champs elysée paris', function(err, res) {
    x.push(res)
    console.log(x);
});

If you need to examine the array after several different geocoder.geocode() executions (or other asynchronous executions) you'd need some other infrastructure to handle that. Research asynchronous functions a bit to find examples on that.

VoteyDisciple
  • 37,319
  • 5
  • 97
  • 97