Skip to content

Instantly share code, notes, and snippets.

@faustoct1
Last active August 8, 2022 04:00
Show Gist options
  • Save faustoct1/75da9eabc0fd175e38c52f3631fd66e7 to your computer and use it in GitHub Desktop.
Save faustoct1/75da9eabc0fd175e38c52f3631fd66e7 to your computer and use it in GitHub Desktop.
Obter url query string em javascript
const test = async () => {
const url = new URL('https://example.com?foo=1&bar=2');
const params = new URLSearchParams(url.search);
console.log(params.get('foo'))
console.log(params.get('bar'))
const entries = params.entries()
for (const item of entries) {
console.log(item)
}
const keys = params.keys()
for (const item of keys) {
console.log(item)
}
}
(async () => test())()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment