String de trás para frente


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var stringOri = "string";
  2. var stringLen = stringOri.length;
  3. var reverse = '';
  4. var x = 0;
  5.  
  6. while(x < stringLen+1){
  7. reverse += stringOri.substr(stringLen-x,1);
  8. x++;
  9. }
  10.  
  11. document.write(reverse); // vai retornar "gnirts"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.