JS Array traversal

Source: Internet
Author: User
JS array The general situation can be traversed in the following ways:
<script type= "Text/javascript" >//such as Var values=new Array (); values[0]= "Beijing"; values[1]= "Tianjin";//other omit//traverse 1for ( var i=0;i<values.length;i++) {alert (values[i]);} Traverse 2for (var ele in values) {alert (Values[ele]);//Subscript}</script>
However, for-in cannot be used in a random situation, the following problems occur:
<script type= "Text/javascript" >var data=[{name: "A", Age:12},{name: "B", Age:11},{name: "C", Age:13},{name: "D", AGE:14}];  for (var o in data) {     alert ("Text:" +data[o].name+ "value:" +data[o].age);   } </script>
The result is not popped four times, but popped eight times, and the other four times are undefined

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.