-8

I want to remove the string from the url and update as it after the removal.

example: www.abc.com/xyz

I need to remove xyz and update it as www.abc.com

Thank you

2 Answers2

1

You can use js split method https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

var url = 'www.abc.com/xyz';
var arr = url.split('/');
var newUrl = arr[0];
console.log(newUrl);

/*if string the url is 'www.abc.com/xyz/pqr' and you want only 'www.abc.com/xyz' thn?*/

var url = 'www.abc.com/xyz/pqr';
var arr = url.split('/');
if(arr.length > 1){
 arr.pop();
}
var newUrl = arr.join('/');

console.log(newUrl);
-1

const url = new URL("https://example.com/test")
url.pathname = "/"

console.log(url.toString())
AlexOwl
  • 869
  • 5
  • 11