Change and add method to String with prototype - Javascript String Operation

Javascript examples for String Operation:String Reverse

Description

Change and add method to String with prototype

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/*from   w  w  w  .  j  ava  2s.co m*/
String.prototype.reverse = function() {
return Array.prototype.reverse.apply(this.split('')).join('');
}
console.log("box".reverse());
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials