Use only necessary fields in an object for URL params
I think you could do this in one go using Object.keys on your formData Object, followed by a few methods from the Array and String prototype.



var formData = { 
  account_name: 'SomeAccountName',
  custom_domain_name: '',
  id: 152
};

var enc = encodeURIComponent;

// create an array from formData props
var query = Object.keys( formData )
// filter by the prop value length
// which will only give you props where the value
// has a length property which is greater than 0.
  .filter( key =&gt; formData[key].length )
// map to acctually add the value to the filtered props
// separated by equal signs.
  .map( key =&gt; enc( key ) + '=' + enc( formData[key] ) )
// add your popup prop
  .concat( 'popup=true' )
// join your array elements to a string separated by &amp;.
  .join( '&amp;' )
// finally add ? to the beginning of the string.
  .replace ( /^/,'?' );

// here is your query string.
console.log(query)
.as-console-wrapper { top: 0; }