Skip to content

Instantly share code, notes, and snippets.

@ilyas-shah
Created June 30, 2021 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyas-shah/9434070f1c0e2b5aa79b94bda8c930dc to your computer and use it in GitHub Desktop.
Save ilyas-shah/9434070f1c0e2b5aa79b94bda8c930dc to your computer and use it in GitHub Desktop.
Generate URL dynamically in JS
const generateURL = (data = {}) => {
const domain = 'http://testurl.bitfinix.com';
let queryString = '';
for (const key in data) {
if (data[key])
queryString += `${key}=${data[key]}&`;
}
return `${domain}/${queryString ? '?' + queryString.slice(0, -1) : ''}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment