If you want to split the string into an array based on the pattern of a number followed by a dot and space, you can use a regular expression (regex) in JavaScript to achieve that.
Here’s an example of using regex to split the string and achieve the desired output:

const inputString = '1. Lorem Ipsum. 2. Lorem Ipsum. 3. Lorem Ipsum';
const outputArray = inputString.split(/\d+\.\s/).filter(item => item !== '');
console.log(outputArray);
// Output: [ '1. Lorem Ipsum.', '2. Lorem Ipsum.', '3. Lorem Ipsum.' ]

Explanation:

split(/\d+\.\s/) uses a regular expression as the argument to split() instead of a simple string. /\d+\.\s/ is a regex pattern that matches one or more digits (\d+), followed by a dot (\.), and a space (\s).

The split() method separates the string into an array based on this regex pattern.
filter(item => item !== ”) is used to remove any empty strings from the resulting array, which might occur due to splitting the string.

Support On Demand!

JavaScript