title: Javascript to allow a whitelist of URL arguments only
body: <p>I am trying to make a whitelist of allowed url args/query strings so any provided args in the url that are not in my whitelist are deleted from the url.</p>
  <p>Here is my code.</p>
  <pre><code>var paramsString = &quot;2=lol&amp;q=how&amp;44=slap&amp;topic=api&amp;1=tr&amp;view=media&quot;; //test url args
  var searchParams = new URLSearchParams(paramsString);
  
  //this whitelist of args are the only args to be allowed in the url
  var url_args_whitelist = [
  &quot;beforeafter&quot;,
  &quot;catid&quot;,
  &quot;childforums&quot;,
  &quot;display&quot;,
  &quot;element_id&quot;,
  &quot;element_type&quot;,
  &quot;exactname&quot;,
  &quot;filter_mediaType&quot;,
  &quot;filter_order&quot;,
  &quot;filter_order_Dir&quot;,
  &quot;filter_search&quot;,
  &quot;filter_tag&quot;,
  &quot;format&quot;,
  &quot;id&quot;,
  &quot;Itemid&quot;,
  &quot;layout&quot;,
  &quot;limit&quot;,
  &quot;limitstart&quot;,
  &quot;messageid&quot;,
  &quot;more&quot;,
  &quot;option&quot;,
  &quot;order&quot;,
  &quot;ordering&quot;,
  &quot;quality&quot;,
  &quot;query&quot;,
  &quot;recently&quot;,
  &quot;recip&quot;,
  &quot;reply_id&quot;,
  &quot;return&quot;,
  &quot;searchdate&quot;,
  &quot;searchf&quot;,
  &quot;searchphrase&quot;,
  &quot;searchuser&quot;,
  &quot;searchword&quot;,
  &quot;sortby&quot;,
  &quot;start&quot;,
  &quot;task&quot;,
  &quot;tmpl&quot;,
  &quot;token&quot;,
  &quot;view&quot;
  ];
  
  for (let p of searchParams) {
  //if the url argument is not in our whitelist of allowed arguments then delete it
    searchParams.delete(p[0]);
  }
  
  console.log(&quot;whitelist output: &quot;, searchParams.toString() );
  </code></pre>
  <p>How can I make my code check against my whitelist and then run my delete function to remove the junk url args.</p>