Loading

「思考题」模拟实现字符串的trim()函数

String.prototype.trim = function () {
    let reg = /(^\s*)|(\s*$)/g
    return this.replace(reg, '')
}


// 测试
let str = '    hello word    '
console.log(str.trim())
// "hello word"
posted @ 2020-04-03 17:33  fsdffsdf  阅读(192)  评论(0)    收藏  举报