Object Array Method

Source: Internet
Author: User

Let's take a short look.Code:
VaR o = {}
Array. Prototype. Push. Call (O, 10 );
/* Note: It must be array. Prototype rather than array, Because push is the method of the array object, not the method of the Array Function */
Alert (O. Length + "-" + O [0]);
It runs normally on Firefox. The result is alert "1-10", but the output on IE is undefined-undefined.
Why?
It turns out that in IE, it is necessary to add a Length attribute to the O object, so that IE will process your own this object like an array. Therefore, the definition of O should be changed:
VaR o = {length: 0 }.
Run again. This time, ie shows that the result is correct.
No wonder there must be a definition of the Length attribute in the jquery object definition.

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.