How to remove a variable from the url when removing the checkbox?

Code example:
let objectWithCheckboxes={},
withParams=!!location.search
siteHref=location.href
$('input').change(e=>{
 let el=e.target
jq=$(el)
 if(jq.is(':checked')) objectWithCheckboxes[el.name]=el.value
 else delete objectWithCheckboxes[el.name]
 let res=[]
 for(let k in objectWithCheckboxes) res.push(k+'/'+objectWithCheckboxes[k])
res=res.length?(withParams?'/':'/')+Res. join('/'):"
window.history.replacestate will(",",siteHref+res)
})

HTML:
<input type="checkbox" class="checkbox" value="1" name="value1">
<input type="checkbox" class="checkbox" value="1" name="value2">
<input type="checkbox" class="checkbox" value="1" name="value3">
<input type="button" value="Apply filter" onClick="location.reload()" />


The problem:
By clicking on the checkboxes in the address bar of the appropriate variables substituted with the value 1, press the "Apply filter" and everything is OK (php implemented that stretched from the url variables and the selected checkboxes remain checked or better is also on js to make?). BUT! After reloading the page, clearing a checkbox (form submission), the address is not deleted values, i.e. they start again (which is not necessary): site.ru/value1/1/value2/1/value1/1/value1/1

Question: how to fix the situation, so after refreshing the page (when you already have the address of the type site.ru/value1/1/value2/1 and removing/adding the first and second checkboxes they removed and again added in the address and not re-added?

P. S. can still advise sensible/understandable to the beginner lessons on js, I have long wanted to start learning at least the basics.
April 3rd 20 at 17:30
0 answer

Find more questions by tags JavaScript