'both' is my object that should hold 2 arrays: eng, fr.
These arrays each, hold multiple objects.
How do I push every value from frDisplayData to fr:[] in my 'both' object:
const displayData = [];
var both = {eng:displayData, fr:[]};
displayData.forEach(function (item) {
// You must call .then on the promise to capture the results regardless of the promise state (resolved or still pending)
translateText(item.explanation, 'fr').then(function(result) {
frExplanation = result;
frTitle = translateText(item.title, 'fr').then(function(result) {
frTitle = result;
frDisplayData = {
date: item.date,
explanation: frExplanation,
hdurl: item.hdurl,
media_type: item.media_type,
service_version: item.service_version,
tite: frTitle,
url: item.url
}
console.log(frDisplayData);
})
});
})
Any simplified solution to this would also help.
Currently, console.log(frDisplayData); gives me the following:
{
date: '2022-03-26',
explanation: "xyz",
hdurl: 'xyz.jpg',
media_type: 'image',
service_version: 'v1',
tite: 'Pluton la nuit',
url: 'xyz.jpg'
}
{
date: '2022-03-27',
explanation: "abc",
hdurl: 'abc.jpg',
media_type: 'image',
service_version: 'v1',
tite: 'Titan Seas reflète la lumière du soleil',
url: 'abc.jpg'
}