Reputation: 91
I just want to remove commas from object displayed in DOM. Actually, I'm getting
,,,TEST STATUS GREEN,,TEST STATUS GREEN,
in my page with below code:
var vitalTest = document.getElementById("vitalComments").innerHTML = systemList[0].comments;
Upvotes: 2
Views: 2783
Reputation: 1113
I would prefer using one of this two methods:
var text = ',,,TEST STATUS GREEN,,TEST STATUS GREEN,';
var result1 = text.replace(/,/g,'')
console.log(result1)
var result2 = text.split(',').join('')
console.log(result2)
Greetings :)
Upvotes: 1
Reputation: 516
if you just want to remove the commas:
systemList[0].comments.join("");
if you want to add space in between values:
systemList[0].comments.join(" ");
if you want to add anything in between values:
systemList[0].comments.join("anything");
reference for using .join() function:
https://www.w3schools.com/jsref/jsref_join.asp
Upvotes: 4