Created
June 30, 2021 08:28
-
-
Save ilyas-shah/9434070f1c0e2b5aa79b94bda8c930dc to your computer and use it in GitHub Desktop.
Generate URL dynamically in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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