GitHub 6521★

Get the value of a param from a URL

JavaScript version

const getParam = (url, param) => new URLSearchParams(new URL(url).search).get(param);

TypeScript version

const getParam = (url: string, param: string): string | null => new URLSearchParams(new URL(url).search).get(param);

Examples

getParam('http://domain.com?message=hello', 'message'); // 'hello'
Follow me on and to get more useful contents.