write reverse iteration - Javascript Statement

Javascript examples for Statement:for

Description

write reverse iteration

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*w  w  w  .  j a v a2s  . c  o  m*/
var name = "this is a test";
var start = "", end = ""
for(var i = 0, j = name.length-1; i < j; i++, j--) {
    end = name.charAt(i) + end
    start += name.charAt(j)
}

if (i === j)
    start += name.charAt(i);

console.log(start + end); 

    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials