Conforming to the following conditionsobjectCalled a pseudo-array:
- Has the length attribute;
- Storing data by index;
- Methods push, pop, etc. without arrays
Pseudo-arrays (array-like arrays) : you can’t call array methods directly or expect the length property to behave differently. You don’t have array push, pop, etc. But you can still iterate over them in the same way you iterate over groups of numbers.
- Typical is the argument function parameter, the jQuery object ($(” div “), for example), and calls to the document. The getElementsByTagname, document. The.childnodes, such as they return objects belong to pseudo array
A pseudo-array is an Object, whereas a real Array is an Array
You can convert pseudo-arrays into real Array objects using the following methods (compatibility issues handling)
function makeArray(c){
try{
return Array.prototype.slice.call(c)
}catch{
var ret = [] ,len = c.length
for(var i = 0; i<len; i++){ ret[i]=c[i] }return ret
}
}
Copy the code
Or an Array. The from ()