function trim() {
let reg = /(^\s*)|(\s*$)/g
let res = this.replace(reg, '')
return res
}
String.prototype.trim = trim
// 测试
let str = ' hello word '
console.log(str.trim())
// "hello word"
「思考题」模拟实现字符串的trim()函数
猜你喜欢
转载自www.cnblogs.com/liea/p/12627792.html
今日推荐
周排行