I'm trying to redirect the browser to the current page but with new parameters when the user selects and option from a drop down. 

From debugging i can see the url i'm trying to go to is exactly as i want it but when i do window.location.href (i've also tried replace() etc.) it just appends the new arguments to the current url instead of replacing it. 

I've tried for two days now to fix this and it's driving me crazy, i've tried every solution i've found online and so far nothing has worked. Hoping someone can help me out here.

an example address i'm trying to achieve and the the script creates is '<http://localhost/wordpress/showroom/?page=2&orderby=price&order=asc>' 

but instead i get '<http://localhost/wordpress/showroom/?page=2&orderby=price&order=asc&orderby=price&order=dsc>'

event though the script produces '<http://localhost/wordpress/showroom/?page=2&orderby=price&order=dsc>'

this is my select

```
<select id="post-sort">
 <option value="orderby=price&order=desc">Price - Highest First</option>
 <option value="orderby=price&order=asc">Price - Lowest First</option>
 <option value="orderby=year&order=desc">Age - Newest First</option>
 <option value="orderby=year&order=asc">Age - Lowest First</option>
</select>

```

and this is my javascript function

```
$(document).ready(function () {
    $("#post-sort").on('change', function (event) {

        var sortValue = this.value;
        var url = JSON.parse(JSON.stringify(window.location.href));

        //get param string
        var urlParamsSection = url.split('?')[1];

        //If has params
        if (urlParamsSection) {
            //Split params
            var urlParams = urlParamsSection.split('&');
            //Loop all params
            urlParams.forEach(urlParam => {
                //if param contains order var => remove
                if (urlParam.indexOf('order') > -1) {
                    url.replace('&' + urlParam, '');
                }
            });

            url += '&' + sortValue;
        } else {
            url += '?' + sortValue;
        }

        console.log(url);
        window.location.href = url;
        return false;
    });
});

```