Files
30-seconds-of-code/snippets/getBaseURL.md
Isabelle Viktoria Maciohsek 920a0c390b Update snippet descriptions
2020-10-19 22:49:51 +03:00

18 lines
433 B
Markdown

---
title: getBaseURL
tags: string,browser,beginner
---
Gets the current URL without any parameters.
- Use `String.prototype.indexOf()` to check if the given `url` has parameters, `String.prototype.slice()` to remove them if necessary.
```js
const getBaseURL = url =>
url.indexOf('?') > 0 ? url.slice(0, url.indexOf('?')) : url;
```
```js
getBaseURL('http://url.com/page?name=Adam&surname=Smith'); // 'http://url.com/page'
```