I'm using array.map to iterate through DOM elements in nodejs/cheerio.
There is my code:
const $ = cheerio.load(html);
const lis = $("table[id*='sortable-']").find('tr');
const lisy = lis.map((i, li) => {
var name = $(li).find('td.h-text-left.over-s-only').text();
var cnt = $(li).text();
return {
content: cnt
}
}).get();
And now, I want to return named objects by "name" variable, but for now, .map returning iterated objects:
0: {"cnt": content}, 1: {"cnt": content}
Insted of this, I want to get objects indexed by every "name" like this:
name: {"cnt": content}, name: {"cnt": content}
Is it possible to name returned object like this?
mapreturns an array.0and1are indices of that array. You're trying to create an object with keysnmonly? That's simply not possible because object cannot contain duplicate keys. Please define your problem clearly.