The code snippet above showcases a function that retrieves data from a JSON array and appends it onto a webpage inside table elements.
//define a function to fetch process status and set icon URL
function setServerProcessesServer1761() {
var url = "Server1761.json";
var $svc = $("#Server1761-processes"); //get reference to <div>
$.getJSON(url, function(data) {
document.getElementById(
"Server1761-processes"
).innerHTML = data.processes
.filter(s => s.Name.value.includes("company_name"))
.map(
s =>
`<table><tr><td>${s.Name.value}</td> <td>${
s.Status
}</td></tr></table>`
);
$("#Server1761-processes").html(function(_, html) {
return html.replace(/runn1ng/g, "<img src='smallgreen.png' />");
});
$("#Server1761-processes").html(function(_, html) {
return html.replace(/fai1ed/g, "<img src='smallred.png' />");
});
}); // you will have to concatenate the entire services request line on line 130
}
//jQuery syntax to run when document is ready
$(function() {
setServerProcessesServer1761();
});
Upon implementation, an issue arises where a comma ,
is added after each table row, as illustrated here:
https://i.sstatic.net/1g1ny.png
To resolve this, I initially checked for commas within the script but found none using CTRL+F
. It then occurred to me that the commas were originating from the JSON entries in the array.
Hence, my query is how can I eliminate these unwanted commas from the JSON array so that the table rows appear seamless without breaks or commas like this: