jQuery.map returns wrapped elements
There are thousands of ways to write JavaScript and many ways to map
over a
collection in JavaScript. The jQuery variant of the function has a couple of
peculiarities that might trip you up however.
First, the arguments to the map function are not (item, index)
like they are
for the Array.prototype.map
function. Instead, they are (index, item)
.
Second, the jQuery map function does not return an array consisting of the values returned from the map function. It instead returns an array of those values wrapped by jQuery.
This can be unexpected when iterating over a set of elements to create an array of derived values.
Tweet