javascript - Why is my while loop stucked? -


i want replace 2 (or more) line breaks in textarea got stucked in infinty loop

here is:

var dateinput = document.getelementbyid("date"); var intindexofmatch = dateinput.value.indexof('\n\n');   while (intindexofmatch != -1){     dateinput .value = dateinput .value.replace('\n\n', '\n');  } 

because haven't changed intindexofmatch

var dateinput = document.getelementbyid("date"); var intindexofmatch = dateinput.value.indexof('\n\n');   while (intindexofmatch != -1){     dateinput .value = dateinput .value.replace('\n\n', '\n');     intindexofmatch = dateinput.value.indexof('\n\n'); } 

better solution though

var dateinput = document.getelementbyid("date").value.replace(/\n{2,}/g, '\n'); 

that replaces whole code, way


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -