Is there a way to convert a string, which is formatted like an ordered list, into an array using JavaScript or TypeScript? This is the format in which data is being returned from the backend.
The string has the following structure:
- Lorem Ipsum. 2. Lorem Ipsum. 3. Lorem Ipsum.
I am looking to transform it into an array that resembles this:
[
'1. Lorem Ipsum.',
'2. Lorem Ipsum.',
'3. Lorem Ipsum.'
]
This transformation will enable me to utilize the data within my Angular template as shown below:
<div>
<ol>
<li *ngFor="let entry of entries">{{entry}}</li>
</ol>
</div>
I have attempted to achieve this using methods such as split()
and JSON.parse()
. However, I am unsure about the correct character to use for splitting the string.
For instance, when running
console.log(this.entries.split(''));
, the result is an array with each word separated. I have also experimented with alternative characters for splitting the string without success.