'Apify do not push items in map function
I have this function that call a new one with _.map function that cycle each element or array
an than it could push items in Apify Storage, but the element of dataset is ever 0.
Why?
const Apify = require('apify')
const _ = require('underscore');
Apify.main(async () => {
let item = {}
let array = []
const dataset = await Apify.openDataset('dataset2', {forceCloud: true});
await mapping([1, 2, 3, 4, 5]);
function mapping(array){
_.map(array, async function (el) {
console.log("====")
console.log(el)
console.log("====")
await dataset.pushData(item) // <---- no items pushed
})
}
});
Solution 1:[1]
The normal map function doesn't support async/await. Either accumulate into a new array and push that or use for (const ... of ...) loop
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lukáš K?ivka |

