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

let str = " zifu    chuan "

function func(str, target)
{
    let arr = str.split('')

    arr.map(function(item, index){

        if(item === target){
            arr.splice(index, 1)

        }
    })
    return arr.join('')
}

console.log(func(str, 'n'))

posted on 2022-03-28 20:20  GameCat  阅读(501)  评论(0)    收藏  举报

导航