Computer >> Computer tutorials >  >> Programming >> Javascript

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


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 −

<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>