objectA
behaves as an array in the sense that it can be iterated over and accessed by index. It is a collection of elements with .someClass
. Therefore, objectA
is array-like
var objectA = jQuery('.someClass');
var first = objectA[0];//first element with someClass
objectA.each(function(){
//do something with each element that has someClass
});
However, objectA
is not a pure js array. Thus, it does not have access to Array.prototype methods. In order to get access to these methods, you will need to use toArray() like
var realArray = objectA.toArray();
realArray.reverse();//now you can use Array.protype methods like reverse()
Finally, it should be noted that when you use toArray
, each item in the array is a DOM element
and no longer a jQuery
object. This can be overcome by wrapping it in $(...)
like
$(realArray[0])