![](/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.