Skip to content

Instantly share code, notes, and snippets.

@chadwithuhc
Created February 7, 2018 04:44
Show Gist options
  • Save chadwithuhc/5128d2234ed634d22ee33ed346785074 to your computer and use it in GitHub Desktop.
Save chadwithuhc/5128d2234ed634d22ee33ed346785074 to your computer and use it in GitHub Desktop.
JavaScript Pro Tips
// Challenge: Pull out the "character" value from the following URL string
// http://localhost:3000/characters/new?character=Art+Vandelay
// Using the `URL()` API, we can pull out the search params without needing to regex, split, or other wonkery
const params = (new URL(url)).searchParams
params.get('character') // Art Vandelay
// `URL()` will also handle uri decoding -- urls with %20, +, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment