Last active
August 8, 2022 04:00
-
-
Save faustoct1/75da9eabc0fd175e38c52f3631fd66e7 to your computer and use it in GitHub Desktop.
Obter url query string em javascript
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 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