Question: this is the URL im

```
http://127.0.0.1/vikum/symfony/web/index.php/messenger/getConversation

```

using i need to get the URL up to 

```
http://127.0.0.1/vikum/symfony/web/index.php/messenger/

```

how to do this in javascript

remember that the number of / may change what i need is to the point before last /

Answer: 
You can use [lastIndexOf()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf) to get the position of the last forward slash and then use [substring()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) to get the url substring up to that point. 

```
var url = "http://127.0.0.1/vikum/symfony/web/index.php/messenger/getConversation";
var indexOfLastFwdSlash = url.lastIndexOf("/");
var shortUrl;
if (indexOfLastFwdSlash === -1) { // no forward slash is found
  // Invalid URL
} else {
  shortUrl = url.substring(0, indexOfLastFwdSlash + 1); // +1 to include the last '/'
}

```

Sample run:

```js
var url = ' http://127.0.0.1/vikum/symfony/web/index.php/messenger/getConversation';
var indexOfLastFwdSlash = url.lastIndexOf("/");
var shortUrl;
if (indexOfLastFwdSlash == -1) {
  // Invalid URL
} else {
  shortUrl = url.substring(0, indexOfLastFwdSlash + 1); // +1 to include the last '/'
}
alert(shortUrl); // alerts 'http://127.0.0.1/vikum/symfony/web/index.php/messenger/'
```
You can use:

```
url.substring(0,url.lastIndexOf('/') + 1);

```