The following code produces an array of ID's:
$('[data-profileid]').map(function(i, elem) {
console.log($(elem).attr('data-profileid'))
})
Result:
432432432
234235324
2349235325
....
But the following code doesn't produce an array of ID's, instead it produces a list something entirely different with junk on the end.
let ids = $('[data-profileid]').map(function(i, elem) {
return $(elem).attr('data-profileid')
})
console.log(ids)
Result:
'68': '324324324234',
'69': '35324543',
'70': '546456456',
'71': '123405325',
options:
{ withDomLvl1: true,
normalizeWhitespace: false,
xmlMode: false,
decodeEntities: true },
_root:
{ '0':
{ type: 'root',
Why isn't it just returning a list of ID's instead of Cheerio objects?
This is intentional, as explicitly described by this project's documentation:
Pass each element in the current matched set through a function, producing a new Cheerio object containing the return values.
As for the motivation: the map method is implemented in this way for parity with jQuery. From jQuery's documentation:
As the return value is a jQuery object, which contains an array, it's very common to call .get() on the result to work with a basic array.
Most helpful comment
This is intentional, as explicitly described by this project's documentation:
As for the motivation: the
mapmethod is implemented in this way for parity with jQuery. From jQuery's documentation: