When I try to capture the value of a Promise in an array outside of .then()
, the array is populated with undefined
(though console.log()
logs the correct values).
async function fetchCoordinates(pluscode) {
let response = await fetch(url);
return await response.json();
}
let places = []
fetchCoordinates(pluscode)
.then(geoinfo => {
console.log(geoinfo)
console.log(geoinfo.plus_code.geometry.location.lat)
places.push(
{position: new google.maps.LatLng(
geoinfo.plus_code.geometry.location.lat,
geoinfo.plus_code.geometry.location.lng
)}
)
})