title: Javascript function to merge / combine two URLSearchParams
body: <p>I am wondering what is the best <strong>most efficient</strong> code in Javascript to merge two URLSearchParams, but where one of them has higher priority, let me explain with two examples.</p>
  <pre><code>const oldParams = 'foo=one&amp;coo=two'
  const newParams = 'roo=three&amp;moo=four'
  </code></pre>
  <p><code>urlCombine(oldParams, newParams)</code> returns <code>foo=one&amp;coo=two&amp;roo=three&amp;moo=four</code></p>
  <p><strong>So far so good</strong>, but let's say we also want to give <code>newParams</code> higher priority so that if the same <code>key</code> exist in both <code>newParams</code> and <code>oldParams</code> the return value should always use the <code>value</code> of <code>newParams</code>, for example.</p>
  <pre><code>const oldParams = 'foo=one&amp;coo=two'
  const newParams = 'coo=three&amp;foo=four'
  </code></pre>
  <p><code>urlCombine(oldParams, newParams)</code> returns <code>foo=four&amp;coo=three</code></p>