How do you convert a string to a character array in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To convert a string to a character array, use the substring() JavaScript method. This displays the character of the string one at a time as a character array.

Example

You can try to run the following code to convert a string to a character array −

Live Demo

<html>
   <head>
      <title>JavaScript Arrays</title>
   </head>
   <body>
      <script>
         var str = "Amit";
         for (var i = 0, j = str.length; i < j; i++) {
            alert(str.substring(i, i + 1));
         }
      </script>
   </body>
</html>
raja
Published on 14-Feb-2018 07:04:08
Advertisements