Apify do not push items in map function

198 Views Asked by At

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
        })
    }
});

this is the screen: apify storage

1

There are 1 best solutions below

1
On

The normal map function doesn't support async/await. Either accumulate into a new array and push that or use for (const ... of ...) loop