title: How to remove empty query params using URLSearchParams?
body: <p>I was working with query params, and got introduced to <a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams" rel="nofollow noreferrer"><code>URLSearchParams</code></a>. I am using it to form this kind of object to query,</p>
  <pre class="lang-js prettyprint-override"><code>const x = {
    a: 'hello World'
    b: 23
    c: ''
  }
  let params = new URLSearchParams(x);
  console.log(params.toString()) // a=hello+World&amp;b=23&amp;c=
  </code></pre>
  <p>Here, I dont want to have that <code>c=</code>, as it's ugly, and my API doesn't need that.</p>
  <p>So, I want this result <code>a=hello+World&amp;b=23</code> (without empty query string)
  But, I couldn't find anything on the MDN Web Docs.</p>
  <p>How am I supposed to do that?</p>
  <p>Doing the following doesn't work, as it seems to directly mutate the <code>params</code> which affects the <code>forEach</code>:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const x = {
    a: 'hello World',
    b: '',
    c: ''
  };
  
  let params = new URLSearchParams(x);
  params.forEach((value, key) =&gt; { // never reaches `c`
    console.log(key, ' =&gt; ', value)
    if (value == '')
      params.delete(key);
  });
  console.log(params.toString());</code></pre>
  </div>
  </div>
  </p>