![](/img/trans.png)
[英]What change should i make in Google Api javascript so it can only show the indian cities without trailing state and india?
[英]How can I trim a string if input is Ramesh-123-india ...my desire output should be only "india""
在材料表中,其中一列必須修剪..例如輸入是 ramesh-123-india,output 應該只作為“印度”來......如何做到這一點
考慮查看split()
。 JavaScript 文檔
您可以傳入它搜索的字符串模式以將其拆分。
1)您可以在此處使用split
const str = "ramesh-123-india"; const result = str.split("-")[2]; console.log(result);
2)您也可以在此處使用正則表達式/\w+$/
作為:
const str = "ramesh-123-india"; const result = str.match(/\w+$/)[0]; console.log(result);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.