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
.
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
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]);
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.