I have a small function I found that takes a string from a textarea
and then puts it into a canvas
element and wraps the text when the line gets to
In case you need to split a string from your JSON, the string has the \n special character replaced with \\n.
Split string by newline:
Result.split('\n');
Split string received in JSON, where special character \n was replaced with \\n during JSON.stringify(in javascript) or json.json_encode(in PHP). So, if you have your string in a AJAX response, it was processed for transportation. and if it is not decoded, it will sill have the \n replaced with \\n** and you need to use:
Result.split('\\n');
Note that the debugger tools from your browser might not show this aspect as you was expecting, but you can see that splitting by \\n resulted in 2 entries as I need in my case: