Get all parameters from url and insert on all hrefs except one

friends, I’m in need of your help. I need to get parameters from the url

ex: www.test.com/?s=1&param=2&param=3

and put in all hrefs on the page, minus the parameter = s. then it would look like this:

ex: href='www.test.com/?param1&param=2'

This is already happening, the problem is that I don’t want to pass to hrefs: the s parameter

complete code:

$(document).ready(function() {
 function querystringToDict(querystring){
    if (querystring.length === 0) {
       return {};
     }
   let queryDict = {}
   querystring.split("&").forEach(function(item) {
      queryDict[item.split("=")[0]] = item.split("=")[1]
   });
      return queryDict;
   }

  var queryDict = querystringToDict(location.search.substr(1));
  var queryHref, queryFinal = {};              
  var lctSearch = location.search;

  $('html a').each(function() {
      // if the href contains www.test.com insert params
     if ($(this).prop('href').includes('www.test.com')){
        if(lctSearch != ''){
           param = $(this).attr('href').split('?')[1] === undefined ? '' : 
                   $(this).attr('href').split('?')[1];
                            
           queryHref = querystringToDict(param);
           queryFinal = Object.assign({}, queryHref, queryDict);
           paramFinal = Object.keys(queryFinal).map(key => key + '=' + queryFinal[key]).join('&');
           $(this).attr('href',$(this).attr('href').split('?'[0].concat('?',paramFinal));
           }
        } 
    }); 
});

Answer

You can exclude it in the function you have written:

querystring
  .split("&")
  .filter(el => el.split("=")[0] != 's')
//              ^^^^^^^^^^^^^^^^^^^^^^^---- exclude the "s" parameter
  .forEach(function(item) {
  queryDict[item.split("=")[0]] = item.split("=")[1]
});