'Remove certain character from string and return into an array

I've got a string that has html tag like this:

var list = "<ul><li><p>example 1st</p></li><li><p>example 2nd</p></li></ul>"

how can I remove every character of The u, p, li tags

so i can get return result in array like this :

['example 1st','example 2nd']


Solution 1:[1]

You can create a div and then find all the text using innerText using querySelectorAll and array#map.

const list = "<ul><li><p>example 1st</p></li><li><p>example 2nd</p></li></ul>";
const div = document.createElement('div');
div.innerHTML = list;
const text = [...div.querySelectorAll('ul li p')].map(element => element.innerText);
console.log(text);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hassan Imam