javascript - How do I use .split() to break up a string into much smaller strings? -


i making code supposed split alphabet each letter on different line. when press submit button, instead of displaying letters, absolutely nothing @ all. not sure why not working.

the output should be:
a:
b:
c:
d:
etc...

any appreciated, please not use jquery.

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"          "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">  <html xmlns:hi="http://www.w3.org/1999/xhtml">  <head>      <title>my string prototype</title>  </head>  <body>  <form action = "#">      <input type="submit" id = "sub" value="submit" onclick = "show_alphabet();"/>  </form>  <script type="text/javascript">      function show_alphabet () {          var str = "abcdefghijklmnopqrstuvwxyz";          str.prototype.sendarray= function (){              str.split("");          };          var arr = str.sendarray();          (var i=0;i>arr.length;i++){              document.writeln(arr+":");          }      }  </script>  </body>  </html>

thanks!

since looks homework, don't answer outright.

1) when split string, pick character split on. ex: splitting ("a b") (a space b). returns array 2 elements. & b.

2) don't need string prototype stuff see in online help. var arr = str.split(... works fine.

3) greater sign should less in loop. wnat repeat while less length, not greater.

4) don't want writeln arr. want writeln arr[i], or i'th element of array.

5) newline in html replace ":" "<br />"


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -