Skip to content

Instantly share code, notes, and snippets.

@justforuse
Created October 13, 2020 13:26
Show Gist options
  • Save justforuse/9497845e03c0cc9fa11db3c636391bb1 to your computer and use it in GitHub Desktop.
Save justforuse/9497845e03c0cc9fa11db3c636391bb1 to your computer and use it in GitHub Desktop.
Parse url search params by vanilla js
// Sometimes this should use location.href
let params = (new URL(document.location)).searchParams;
let name = params.get('name'); // is the string "Jonathan Smith".
let age = parseInt(params.get('age')); // is the number 18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment