string split method (each in line) javascript -
i'm trying write code program allow user enter word or sentnce in text-box press button.
when user press button result should appear
actually faced problem in last part split sentence , put each in separate line.
what know can put them in separate line write code such that:
var mystring = "zero 1 2 3 four"; var mysplitresult = mystring.split(" "); for(i = 0; < mysplitresult.length; i++){ document.write("<br /> element " + + " = " + mysplitresult[i]); }
but when did it, didn't work
code
function t { var r=input.split("."); (var = 0; < r.length; i++){ r.innerhtml ="<br/> " + r[i];} }
for (var = 0; < n.length; i++) { result.innerhtml = "lenrth of input string: "+ input.length + "<p>number of spaces: "+num +"</p>" + "<p> replacing word 'red' 'blue': "+ input.replace("red" , "blue")+"</p>" + "<p>spilting at'.':</p><br/> " + n[i]; }
this way, assign result.innerhtml
, overwrite each loop turn - output notice 1 last loop turn. instead, should build html string part-by-part (including repetion), , assign whole thing.
var html = "<p>length of input string: " + input.length + "</p>"; html += "<p>number of spaces: " + num + "</p>"; html += "<p> replacing word 'red' 'blue': " + input.replace("red" , "blue") + "</p>"; html += "<p>spilting @ '.':<ul>"; (var = 0; < n.length; i++) { html += "<li>" + n[i] + "</li>"; } html += "</ul></p>"; result.innerhtml = html;
Comments
Post a Comment