Last active
January 31, 2018 13:31
-
-
Save letanure/55005b619ec5708be0f4bf89deb600c1 to your computer and use it in GitHub Desktop.
string_html_list_to_array.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myHtml = '<p>Atesto para os devidos fins que o paciente este internado por três principais motivos:</p> <ol><li> Esta com fome</li><li>Esta com Sede</li><li>Esta com Frio</li></ol>' | |
const arrayItems = myHtml | |
.replace('</ol>', '') | |
.replace(/<\/li>/gi, '') | |
.split('<ol>')[1] | |
.split('<li>') | |
.map(item => item.replace('</li>', '').trim()) | |
.filter(item => item !== '') | |
console.log(arrayItems) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myHtml = '<p>Atesto para os devidos fins que o paciente este internado por três principais motivos:</p> <ol><li> Esta com fome</li><li>Esta com Sede</li><li>Esta com Frio</li></ol>' | |
const temp = new DOMParser().parseFromString(myHtml, 'text/html') | |
const arrayItems = Array.from(temp.querySelectorAll('li')).map(item => item.innerText) | |
console.log(arrayItems) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment