I don't know how to remove the commas when result is displayed on my website.
let regex = /\W/g;
let string = "How are you today?";
let string2 = "48%"
let result = string.match(regex);
let result2 = string2.match(regex);
document.getElementById("header").innerHTML = result;
document.getElementById("head").innerHTML = result2;
<p id="header"></p>
<p id="head"></p>
CodePudding user response:
innerHTML expects a string. You are setting it to an array. So the engine runs toString() on the array which returns all the indexes separated by a comma.
If you want to control how it is outputted, you need to use the join() method.
No character would be result.join('')