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 ));}