Smit Patel Smit Patel - 3 months ago 10
Javascript Question

can i pass array that contain dictionary object into async map

function(req, res, next) {
var products = [
{ id: 1, userid: 12, quntity: 12, productid: 15 },
{ id: 2, userid: 12, quntity: 8, productid: 16 }
];
console.log("------1.here-----");
// async MAP pass products array in it..
async.map(products, upProduct, function(err, result) {
console.log("------3.here-----");
if(err) {
console.log(err);
}
console.log(result);
});
function upProduct(cb) {
console.log("------2.here-----");
cb(null, products);
}
});
},


I can have a console.log 2.here but not get console.log 3.here
can you give me suggestion

Answer

use this code ,

function(req, res, next) {
            var products = JSON.parse(req.body.products);

            console.log("------1.here-----");
            // async MAP pass products array in it.. 

             function upProduct(obj,cb){               
                cb(null,products);
            } 
            async.map(products,upProduct,function(err, result){
                console.log("------3.here-----");
                if(err){
                    console.log(err);
                }
                console.log(result);                
            });            
}
Comments