Reputation:
How can I trim the below URL using javascript in react native? this is the URL
I need to trim this to economictimes.indiatimes.com
.
Upvotes: 0
Views: 765
Reputation: 4770
You can do something like this
const url = "https://economictimes.indiatimes.com/industry/banking/finance/banking/is-indias-current-banking-crisis-just-old-wine-in-a-new-bottle/articleshow/71451268.cms";
const result = new URL(url).host;
console.log(result); // prints "economictimes.indiatimes.com"
You can see more about the URL
interface here
Upvotes: 2
Reputation: 389
url = "https://economictimes.indiatimes.com/industry/banking/finance/banking/is-indias-current-banking-crisis-just-old-wine-in-a-new-bottle/articleshow/71451268.cms"
console.log(url.split("//")[1].split('/')[0]);
Try this!
Upvotes: 0
Reputation: 8232
try this.
url = "https://economictimes.indiatimes.com/industry/banking/finance/banking/is-indias-current-banking-crisis-just-old-wine-in-a-new-bottle/articleshow/71451268.cms"
var arr = url.split("/");
console.log(arr[2]);
Upvotes: 0