How to change string to be displayed as a subscript using JavaScript?

JavascriptWeb DevelopmentFront End Technology

To change the string to be displayed as a subscript using JavaScript, use the sub() method. This method causes a string to be displayed as a subscript as if it were in a <sub> tag.

Example

You can try to run the following code to change the string to be displayed as a subscript −

Live Demo

<html>
   <head>
      <title>JavaScript String sub() Method</title>
   </head>
   
   <body>
      <script>
         var str = new String("Demo Text");
         document.write("This is subscript: "+str.sub());
      </script>
   </body>
</html>
raja
Published on 18-Jan-2018 17:04:32
Advertisements