I'm trying to write a collection of Json objects into an array whilst looping through a fetch operation in Node JS. I'm sure the issue is something to do with it being an Async operation, but can't figure out how to get round it.
This is my code:
for (const car of carFilter) {
const carJson = fetch(modelUrl + car, settings)
.then(res => res.json())
.then((json.data.trim));
carData.push(carJson);
}
console.log(carData);
All I'm getting from the console.log is:
Promise { <pending> },
Promise { <pending> },... etc
Which I presume means I'm trying to do the console.log before the data has been push into the array. I may be wrong.
Thanks in advance.