I'm trying to split the string by word count, the below example is split by character count.
eg. I have 25 words of content.
var text = `Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean commodo ligula eget dolor.
Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur.`
var part1 = text.substr(0, text.substr(0, text.length > 100 ? 100 : text.length ).lastIndexOf(" "));
var part2 = text.substr(text.substr(0, text.length > 100 ? 100 : text.length ).lastIndexOf(" "));
console.log(part1);
console.log(part2);
the output will be like this : part 1
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean commodo ligula eget dolor
part 2
Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur.
How to achieve the same output by word count, like 10 words in part 1 and remaining in part 2
note: The format of the content should print as it is.