At the end of the "JavaScript" array definition, do not leave a comma

Source: Internet
Author: User
Tags array definition javascript array

In JavaScript, if you define a data in the following way,

<script>var Array=[1,2,3,4,];for (var i=0;i<array.length;i++) {alert (array[i]);} </script>

Then the parsing method of this array on different Web pages is different.

In the IE series, at least IE6-IE8 would think that the length of the array is 5, and the last element is undefined


In the Firefox wild Fox Zen, the length of this array is considered to be 4, and the last element is 4.


Although we usually do not define a ambiguity array like this, note that in conjunction with the server language aspx,jsp,php produce a JavaScript array, you will most likely unknowingly define an ambiguity array.

This is likely to cause some JavaScript statements that you cannot run.

Therefore, in conjunction with the server language aspx,jsp,php produce a JavaScript array, you need to pay attention to the end of your array do not leave a comma.

At the end of the "JavaScript" array definition, do not leave a comma

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.