You need to do two things:
- Grab the content from the TextArea
- Loop through the lines and trim each one (removing any empty lines)
CODE:
var content = myTextArea.value;
//Split into lines
var lines = content.split( /\r?\n/ );
//Your new content
var newContent = "";
//Loop through all lines
for ( var i = 0; i < lines.length; i++ )
{
//Trim it first
var line = lines[ i ].trim();
//Empty line, remove it
if ( line === "" ) continue;
//Add to new content
newContent += line + "\n";
}
//Save to text area
myTextArea.value = newContent;
solved Remove space from string and write text in separated line