title: In react, how to pass an array of object as a query string to the endpoint url?
body: <p>I am working on a react app and need to build the the query string dynamically and append it to the url. The reason being is because I have a base endpoint which is same for all the links. However for some links, the api expects 2 parameters while for some it only requires 1 parameter. Depending on the link that you click, the page displays different data.</p>
  <p>For example, I have the following 4 links on the page.
  Comments | View All Sequences | Review | Summary</p>
  <ul>
  <li>Comments link: requires 2 parameters (dstrNr and rgsnId)</li>
  <li>View All Sequences: requires only 1 parameter (dstrNr)</li>
  <li>Review: requires only 1 parameter (dstrNr)</li>
  <li>Summary: requires 2 parameters (dstrNr and rgsnId)</li>
  </ul>
  <p>If I have a base url defined, how can I use the same api action and append the parameter list as an array of object to the url?</p>
  <p>I tried the following by passing the <code>object</code> data as a parameter but it also send <code>undefined</code> object key/value pair to the endpoint as well which I don't want:</p>
  <pre><code>var str = [];
      for (var data in obj)
        if (obj.hasOwnProperty(data)) {
          str.push(encodeURIComponent(data) + &quot;=&quot; + encodeURIComponent(obj[data]));
        }
        console.log(&quot;ENDPOINT&quot; + str.join(&quot;&amp;&quot;)) 
  </code></pre>
  <p>Any help would be appreciated.</p>