Skip to content

Instantly share code, notes, and snippets.

@codeyourwayup
Created August 18, 2020 03:33
Show Gist options
  • Save codeyourwayup/cbb7e7063f9fd9247d19325af4284b88 to your computer and use it in GitHub Desktop.
Save codeyourwayup/cbb7e7063f9fd9247d19325af4284b88 to your computer and use it in GitHub Desktop.
const objectToQueryString = queryParameters => {
return queryParameters
? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {
const symbol = queryString.length === 0 ? '?' : '&';
queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : '';
return queryString;
}, '')
: '';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment