split string by new line javascript code example
Example 1: split text by new line javascript
myText.split(/\n/)
Example 2: string split javascript
var myString = "An,array,in,a,string,separated,by,a,comma";
var myArray = myString.split(",");
/*
*
* myArray :
* ['An', 'array', 'in', 'a', 'string', 'separated', 'by', 'a', 'comma']
*
*/
Example 3: string split javascript newline
let string = "Hi\nHow are you?"
let newstrings = string.split("\n"); // [ "Hi", "How are you?" ]