In JS, arrays are special objects, all objects have properties, arrays have, arrays represent collections of ordered data, and objects represent collections of unordered data.
What is the pseudo-array, of course, it is also an object, pseudo-arrays generally have the following characteristics:
- storing data by index;
- has the length property;
- No array of push, shift, pop, and other methods;
The arguments object of the function, as well as the NodeList object returned by getElementsByTagName, Ele.childnodes, or some custom object, can be pseudo-arrays.
We can convert a pseudo-array to a standard array in the following ways:
1, using Array.prototype.slice.call () or [].slice.call ();
Array.prototype.slice.call ({ 0: "Hello", 1:12, 2:true, Length:3 }); //
2, the use of ES6 Array.from method;
Array.from ({ 0: "Hello", 1:12, 2:2013, 3: "University" , Length:4 }); // ["Hello", 12, 2013, "University"]
What is a pseudo-array in javascript? How do I convert a pseudo-array into a standard array?