const obj="中国,美国,英国,法国,德国," //方法一: const result1 = obj.substring(0, obj.lastIndexOf(',')); //方法二: const result2 = (obj.substring(obj.length - 1) == ',') ? obj.substring(0, obj.length - 1) : obj; //方法三: const result3 = obj.substring(0,obj.length-1); //方法四: const reg = /,$/gi; const result4 = obj.replace(reg,""); //结果输出: console.log('方法1:',result1) console.log('方法2:',result2) console.log('方法3:',result3) console.log('方法4:',result4)
标签: lastIndexOf, substring, 删除逗号, 字符串, 特殊符号
上面是“js去除字符串最后一个特殊符号(如:逗号、顿号等)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2008.html
workflows工作流
外星人ComfyUI工作流
一只可爱的毛茸茸的猫ComfyUI工作流
一个港口配备了小型船只、起重机、集装箱和码头
一个孤独的身影在未来主义城市
一个穿着发光红色长袍的人
城市里出现一只可爱的小生物ComfyUI工作流
一只穿着黑色蝴蝶结西装可爱橙色小猫
一个浑身皮毛看起来像丘巴卡的3d动漫人物
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!