1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>数组拍平最优解</title> 6 </head> 7 <body> 8 <script> 9 10 var args = ["a", "b", "c",["www","qqqqq",["aaaa","eeeeee"]]]; 11 function isarry(arr){ 12 13 return Object.prototype.toString.call(arr) === "[object Array]" ; 14 } 15 var result = []; 16 function cc(arr){ 17 for(var i = 0;i<arr.length; i++){ 18 if(!isarry(arr[i])){ 19 result.push(arr[i]); 20 } else{ 21 cc(arr[i],result) 22 } 23 } 24 return result; 25 } 26 27 console.log(cc(args)); 28 29 </script> 30 </body> 31 </html>