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
Post a Comment