Hi =) I have some code that I am struggling with. I have a function to replace specific html characters values like a tab or new line, however it doesn't seem to work very well.
var replaceHTMLCharacters = function(text){
text = text.split("");
for(var i = 0; i < text.length; i++){
if(text[i].charCodeAt(0) == 10){
text[i] = "\n";
}
}
text = text.join("");
console.log(text);
return text;
}
This is an example of me trying to remove a new line character and replace it with "\n" so that I can store it in a JSON format. It reaches the point where it says text[i] = "\n"
but then doesn't actually set this character to a "\n"
. Can anyone tell me what I am doing wrong? Thank you.