This is simple method to traverse a string char by char using JavaScript. Here using charAt() built in function to process each letter of text.
<!DOCTYPE html> <html> <head> <script> function myFunction(){ var str = "abcd"; var len = str.length; for(i=0;i<len;i++) { var str2 = str.charAt(i); alert(str2); } } </script> </head> <body> <button onclick="myFunction()">Click Here</button> </body> </html>
Try Output Here :
No comments:
Write comments