Files
30-seconds-of-code/snippets/getBaseURL.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

533 B

title, tags, author, cover, firstSeen, lastUpdated
title tags author cover firstSeen lastUpdated
Get base URL string,browser,regexp chalarangelo compass 2020-05-03T12:20:54+03:00 2021-01-03T20:32:13+02:00

Gets the current URL without any parameters or fragment identifiers.

  • Use String.prototype.replace() with an appropriate regular expression to remove everything after either '?' or '#', if found.
const getBaseURL = url => url.replace(/[?#].*$/, '');
getBaseURL('http://url.com/page?name=Adam&surname=Smith');
// 'http://url.com/page'