Tue29 Function: String.reverse() Posted on Aug 29, 2006 in Code, JavaScript | 2 comments Prototype function to reverse the contents of a string. 1234567891011String.prototype.reverse = function() { var reversed = ""; var i = this.length; while (i>0) { reversed += this.substring(i-1, i); i--; } return reversed; }
tanvir June 9, 2008 what about … String.prototype.reverse = function(){ this.split(”).reverse().join(”) }
what about …
String.prototype.reverse = function(){
this.split(”).reverse().join(”)
}
Nice! That’s much more elegant. I’ll have to try it out.