// split sentence into words
sentence.split(' '); // split the string on the spaces
const splitText = (string) => {
const newText = string
.split(/((?:w+ ){1})/g)
.filter(Boolean)
.join("
");
return newText
};
console.log(splitText("Hello, world"));
//Hello,
//world