Prototype function to reverse the contents of a string.

1
2
3
4
5
6
7
8
9
10
11
String.prototype.reverse = function()
{
  var reversed = "";
  var i = this.length;
  while (i>0)
  {
    reversed += this.substring(i-1, i);
    i--;
  }
  return reversed;
}