Javascript String ReverseString()

Description

Javascript String ReverseString()


String.prototype.ReverseString=function  () {
  
  var rev="";

  for (i=this.length-1;i>=0;i--){
    rev=rev+this[i];//from   w w w  .  ja v  a 2  s  .c  o m
  }
  return rev;

}

Javascript String reverseString()

String.prototype.reverseString = function(){
  return this.split('').reverse().join('');
};

'hello world'.reverseString();
// dlrow olleh//from w  ww  .j av  a2 s.c o m

Javascript String reverseString()

function reverseString(str) {
  if (!str || str.length < 2) return str;
  
  return str.split('').reverse().join('');
}

// String extension: 

String.prototype.reverseString = function () {
  if(!this || this.length < 2) return this;
  
  return this.split('').reverse().join('');
}



PreviousNext

Related