萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> 一個JavaScript遞歸實現反轉數組字符串的實例

一個JavaScript遞歸實現反轉數組字符串的實例

 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <!DOCTYPE html>  <html>  <head>  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  <title>每天一個JavaScript實例-遞歸實現反轉數組字符串</title>  <script>  var func = function(x,indx,str){    return indx == 0 ? str : func(x,--indx,(str +=" " + x[indx]));;    }  var arr = new Array("apple","banna","orange","apple2","apple3");  var arr1 = arr.slice(0)  var arr3 = func(arr1,arr1.length,"");  var arr2 = arr.slice(0).reverse();  console.log(arr2);  console.log(arr);  console.log(arr3);      </script>  </head>      <body>      <div id = "date">  </div>      </body>  </html>
copyright © 萬盛學電腦網 all rights reserved