javascript技巧

关注公众号 jb51net

关闭
首页 > 网络编程 > JavaScript > javascript技巧 > 递归实现反转数组字符串

一个JavaScript递归实现反转数组字符串的实例

投稿:whsnow

这篇文章主要介绍了一个JavaScript递归实现反转数组字符串的实例,很不错,非常适合新手朋友们
  <!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> 
您可能感兴趣的文章:
阅读全文