for replacing all occurrence of a string, you should use regular expressions.
Example https://davidwalsh.name/javascript-replace
Or for temporary solution you can use
<p id="demo">My Output</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var names = "(Ajar,Sentinel,Manor,),(Dagwood,Steve,Guru,)";
var res = names.replace(",)", ")").replace(",)", ")");
document.getElementById("demo").innerHTML = res;
}
</script>
For all Purpose Following code is working fine
function myFunction() {
var names = "(Ajar,Sentinel,Manor,),(Dagwood,Steve,Guru,),(a,b,c,),(p,q,r,),(dfg,)";
var res = names.replace(/\,\)/g,')');
document.getElementById("demo").innerHTML = res;
}