JS traversal array and print array instance analysis _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how to traverse and print arrays by JS, and analyzes the techniques related to JavaScript Array traversal and print output by using examples, if you need it, you can refer to the examples in this article to analyze the JS traversal array and print the array method. We will share this with you for your reference. The details are as follows:

I have been suffering from headaches and JS print arrays, and I didn't see any good method. I wrote a simple method for backup.

// Traverse the array var dd = {'A': '123', 'B': '123', 'C ': '000000'} dd ['D'] = ['000000', '000000']; // traverses the Array function scan_array (arr) {for (var key in arr) {// This is the key if (typeof (arr [key]) = 'array' | typeof (arr [key]) = 'object ') {// recursively call scan_array (arr [key]);} else {document. write (key + '=' + arr [key] +'
') ;}} Function successionPrint (str, num) {num = parseInt (num); var return_str = ''; for (var I = 1; I <= num; I ++) {return_str + = str;} return return_str;} function _ debug (param, flag) {if (! Param | typeof (param) = 'number' | typeof (param) = 'string') {return param;} var t = typeof (param) + '(\ n'; flag = flag? ParseInt (flag) + 1: 1; for (var key in param) {if (typeof (param [key]) = 'array' | typeof (param [key]) = 'object') {var t_tmp = key + '=' + _ debug (param [key], flag); t + = successionPrint ('\ t', flag) + t_tmp + '\ n';} else {var t_tmp = key +' = '+ param [key]; t + = successionPrint (' \ t', flag) + t_tmp + '\ n' ;}} t = t + successionPrint (' \ t', flag-1) + ')'; return t;} function _ debug (param) {alert (_ debug (param ));}

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.