How can I parse an HTML string in JavaScript?

For server-side JavaScript or Node.js, using a library like cheerio is a fantastic choice. It’s like jQuery for the backend and gives you the ability to parse HTML without needing a full DOM. Here’s how you can do it with cheerio

const cheerio = require('cheerio');
const htmlString = "<a href='link1'>One</a><a href='link2'>Two</a>";
const $ = cheerio.load(htmlString);
$('a').each((i, el) => console.log($(el).attr('href')));

It’s lightweight, efficient, and great for parsing HTML when you’re working in environments that don’t have a browser DOM available. This is an awesome way to “javascript parse html” on the server.