title: Get the array of objects from query parameters in javascript
body: <p>I'm trying to parse the array from the url query parameters. The url is as below which contains the array of emp objects specified in query parameters</p>
  
  <pre><code>http://localhost:8080/list?emp[0].id=21&amp;emp[0].name=john&amp;emp[1].id=22&amp;emp[1].name=tom
  </code></pre>
  
  <p>Can someone please help me with the function that will parse such query params(with some ReGEX maybe) and returns the array as below</p>
  
  <pre><code>[{id:'21',name:'john'},{id:'22',name:'tom'}]
  </code></pre>
  
  <p><strong>Note:</strong> There could be any number of emp objects mentioned in the query params, for example purpose I've just added two.
  I've looked for similar solutions but none of them seems to return the array which has its objects specified in the query params with the index value. So please don't mark the question as duplicate</p>
  
  <p><strong>Edit:</strong> I've written the below function which works for fetching simple query params but doesn't work for array of objects specified in query param as above.</p>
  
  <pre><code>export const getQueryParamByName = (name, url) =&gt; {
      if (!url) url = window.location.href;
      name = name.replace(/[[\]]/g, '\\$&amp;');
      const regex = new RegExp('[?&amp;]' + name + '(=([^&amp;#]*)|&amp;|#|$)');
      const results = regex.exec(url);
      if (!results) return null;
      if (!results[2]) return '';
      return decodeURIComponent(results[2].replace(/\+/g, ' '));
  }
  </code></pre>