去除字符串中最后一个指定的字符

function deleteLastStr(origin, str) {
if (typeof origin === "string" && typeof str === 'string') {
var arr = origin.split('')
arr.splice(origin.lastIndexOf(str), 1);
return arr.join('');
} else {
throw "数据类型错误";
}
}
console.log(deleteLastStr('origin', 'n'));// origi
demo演示地址:http://demo.crazyming.com/?link=topic/d3/去除字符串中最后一个指定的字符.html
版权声明:
作者:东明兄
链接:https://blog.crazyming.com/note/practice/1600/
来源:CrazyMing
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
海报
去除字符串中最后一个指定的字符
javascript去除字符串中最后一个指定的字符


共有 0 条评论