html - How to replace a new line character in Javascript? -


hi =) have code struggling with. have function replace specific html characters values tab or new line, doesn't seem work well.

var replacehtmlcharacters = function(text){   text = text.split("");     for(var = 0; < text.length; i++){         if(text[i].charcodeat(0) == 10){             text[i] = "\n";         }     }   text = text.join("");   console.log(text);   return text; } 

this example of me trying remove new line character , replace "\n" can store in json format. reaches point says text[i] = "\n" doesn't set character "\n". can tell me doing wrong? thank you.

"\n" newline character. you're replacing them what's there, leaving string unchanged. if want actual characters \ , n, need mask backslash \\n , insert that.


Comments