What is a pseudo-array in javascript? How do I convert a pseudo-array into a standard array?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.