I have a string that I would like to split in an array that has (for example) 3 words per index. What I would also like to do is to meet a new line character in this line so that it “skips” the 3 word limit and puts it in a new index and starts adding words to this new index until it reaches 3 again, Example
var text = "this is some text that I'm typing here \n yes I really am"
var array = text.split(magic)
array == ["this is some", "text that I'm", "typing here", "yes I really", "am"]
I tried looking for regular expressions, but so far I can’t understand the meaning of the syntax used in regex.
I wrote a way to a complex function that splits my string into lines of 3, first breaking it into an array of individual words, using .split(" ");, and then using a loop to add it 3 in each array. But with this I can not accept the new line symbol.
source
share