Is there a better way?

Hi all,

So, I’m currently undertaking a work-related task and I’m looking for a little feedback/debate.

Essentially I’m in the process of writing a script that I can save into every config I create (config = we scrape clients websites and put that data on our site).

I’ve started with converting HTML entities (hex codes) to readable text and for my script to .match the entity, then replace it with the correct value.

See the snippet below for how I’m looking to do this, however, now that I’ve started it, I’m wondering if there is a cleaner way to write this so I don’t have hundreds of if/else statements.

Example below.

if (salary.match(/ /) || salarydesc.match(/ /) || title.match(/ /) || description.match(/ /))
{
	salary = salary.replace(" ", "	");
	title = title.replace(" ", " ");
	description = description.replace(" ", " ");
	salarydesc = salarydesc.replace("ü", " ");
}
else if (salary.match(/!/) || salarydesc.match(/!/) || title.match(/!/) || description.match(/!/))
{
	salary = salary.replace("!", "!");
	title = title.replace("!", "!");
	description = description.replace("!", "!");
	salarydesc = salarydesc.replace("ü", "!");
}

Any advice would be well great, can’t help but feel amateuerish but it’s the only way I’ll get better.

Thanks

Maybe this helps: you could use textContent

document.getElementById("salary").textContent

This will automatically convert your entities