user19461854
user19461854

Reputation: 15

Remove commas from regex using JavaScript

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>

Upvotes: 0

Views: 42

Answers (1)

epascarello
epascarello

Reputation: 207557

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('')

Upvotes: 1

Related Questions