I have this string:
<ol>
<li><strong>Pro</strong>Something is written here.</li>
<li>Another one here.</li>
</ol>
I need to convert just the contents of the <li></li>
to an array, if at all possible.
Suggestions?
I have this string:
<ol>
<li><strong>Pro</strong>Something is written here.</li>
<li>Another one here.</li>
</ol>
I need to convert just the contents of the <li></li>
to an array, if at all possible.
Suggestions?
You could use a DOMParser.
For example:
var parser = new DOMParser();
var html = `<ol>
<li><strong>Pro</strong>Something is written here.</li>
<li>Another one here.</li>
</ol>`;
var doc = parser.parseFromString(html, "text/html");
var listItems = doc.querySelectorAll("ol li");
var arr = [];
for (var i = 0; i < listItems.length; i++) {
arr.push(listItems[i].innerHTML);
}
console.log(arr);