Created
April 9, 2024 09:03
-
-
Save oscarmarina/0eb66cd59b41077f0d8c74517be6740c to your computer and use it in GitHub Desktop.
converting-a-url-object-to-a-plain-object-in-java-scrip
This file contains 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
// https://www.abeautifulsite.net/posts/converting-a-url-object-to-a-plain-object-in-java-script/ | |
const url = new URL('https://api.chucknorris.io/jokes/random'); | |
function urlToPlainObject(url) { | |
const plainObject = {}; | |
for (const key in url) { | |
if (typeof url[key] === 'string') { | |
plainObject[key] = url[key]; | |
} | |
} | |
return plainObject; | |
} | |
console.log(urlToPlainObject(url)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment