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
textarea
canvas
Split string in JavaScript
var array = str.match(/[^\r\n]+/g);
OR
var array = str.split(/\r?\n/);