I'm trying to return an object from an array map inside a for loop and push it to productsData array but I'm getting [ [Object], [Object] ]. The array in question is 'lol'. Here's the code below:
for (let i = 0; i < productsUrls.length; i++) {
let ficheTechnique = [];
let request = await axios.get(productsUrls[i]);
const $ = cheerio.load(request.data);
let productUrl = productsUrls[i];
let title = $('div.col10').find('h1.-fs20.-pts.-pbxs').text();
let price = $('div.-phs').find('div span.-b.-ltr.-tal.-fs24').text();
let description = $('div.card.aim.-mtm').find('div.markup.-mhm.-pvl.-oxa.-sc').text();
let descriptionImg = $('div.card.aim.-mtm').find('div.markup.-mhm.-pvl.-oxa.-sc center img').attr('data-src');
let lol = $('.row.-pas article').map((i, el) => {
let h2 = $(el).find('h2.hdr.-upp.-fs14.-m.-pam').text();
let characteristiques = $(el).find('.markup.-pam').text() || $(el).find('.-pvs.-mvxs.-phm.-lsn').text();
return {
h2,
characteristiques
};
}).get();
console.log('ficheTechnique', lol);
productsData.push({
productUrl,
title,
// price,
// description,
// descriptionImg,
// ficheTechnique,
lol
})
}
Your map
call is returning an array of objects, each containing h2
and characteristiques
attributes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.