I'm trying to put element in an array that have been define externaly a method.
let result = JSON.parse(body);
let objects = [];
result.results.forEach(element => {
getObjectDetail(element.place_id).then((detail) => {
console.log(detail);
let object = {
place_id: element.place_id,
name: element.name,
rating: element.rating,
address: detail.result.formatted_address,
photo:
googleApiHost +
googlePlacePrefix +
googlePlacesPlaceImageUri +
'?key=' +
googleApiKey +
'&maxwidth=400&photoreference=' +
element.photos[0].photo_reference,
website: detail.result.website
}
console.log(object);
objects.push(object);
});
});
console.log(objects);
console.log(object) give me the good result with all fields setted.
But console.log(objects) return an empty array