substr、substring、slice的区别

时间:2020-09-17 14:04:10   收藏:0   阅读:51

slice()substring()substr()这三个方法都是返回被操作字符串的一个子字符串,那么他们有啥区别呢?

共性

// log
let x = ‘hello‘
console.log(x.slice(1))
console.log(x.substring(1))
console.log(x.substr(1))
console.log(x)

特性

第二个参数比第一个参数小

// log
let x = ‘hello‘
console.log(x.substr(3, 1)) // 正常使用
console.log(x.slice(3, 1) === ‘‘)
console.log(x.substring(3, 1))

原文:https://www.cnblogs.com/oceans/p/13683694.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!