Ответ 1
Это потому, что jQuery.fn.map
возвращает новый объект jQuery, вы должны использовать jQuery.fn.get
для получить массив:
var a = $('a').map(function(v, node) {
// v is the index in the jQuery Object,
// you would maybe like to return the domNode or the href or something:
// return node.href;
return v;
}).get(); // <-- Note .get() converts the jQuery Object to an array
Микро-оптимизация:
Если вы посмотрите на исходный код для jQuery.fn.get
, вы увидите, что он указывает на jQuery.fn.toArray
:
function ( num ) {
return num == null ?
// Return a 'clean' array
this.toArray() :
// Return just the object
( num < 0 ? this[ this.length + num ] : this[ num ] );
}
Итак, вы также можете позвонить:
$('a').map(...).toArray();