-1
 function replaceAll(find, replace, str) {
   //find=\n replace=<br/>
   //str=tyyrtu\nuiop\nuioui
            try {
                while (str.indexOf(find) > -1) {
                    str = str.replace(find, replace);
                }
                return str;
            }
            catch (e) { }
        }

how to replace \n in string to
in javascript? pls help me fix this issue

zmo
  • 24,463
  • 4
  • 54
  • 90
  • HTML does not have a closing slash on `
    `. Though not invalid, it serves no purpose, browsers are instructed to ignore it, it does nothing and is, therefore, pointless and only takes up space needlessly.
    – Rob May 01 '17 at 11:16

1 Answers1

0

 function replaceAll(find, replace, str) {
    try {
       str = str.replace(new RegExp(find,"g"), replace);
     }
     catch (e) { }
     return str;
 }
 var input = "qqq\nwww\n eee\n rrrr";
 var output = replaceAll("\n", "</br>", input);
 console.log("output:" + output);
Ajay
  • 2,483
  • 2
  • 16
  • 27