Javascript - Reverse a String


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

Just a simple snippet on how to reverse a string using a for loop.


Copy this code and paste it in your HTML
  1. var aString = "Hotel";
  2. var rString = "";
  3. for(var i = aString.length; i>=0; i--){
  4. rString += aString.substr(i,1);
  5. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.