当前位置:网站首页>判断字符串首尾是否包含目标参数:startsWith()、endsWith()方法
判断字符串首尾是否包含目标参数:startsWith()、endsWith()方法
2022-04-23 06:24:00 【资深咸鱼~】
startsWith():表示参数字符串是否在原字符串的头部,返回布尔值
endsWith():表示参数字符串是否在原字符串的尾部,返回布尔值
应用:
let str = 'wo?e'
console.log(str.endsWith()); // false
console.log(str.startsWith('w')) //true
console.log(str.startsWith('')) //true
console.log(str.endsWith('')) //true
console.log(str.endsWith('e')) //true
console.log(str.endsWith('?', 3)); // true
从例子中我们可以看出:
1、当字符串调用 endsWith()
方法时不传参数时,默认是 undefined
返回的结果是 false;
2、在查找空字符串时,返回的结果是 true,那是因为空字符在任何字符串中都是存在的;
3、当有第二个参数的时候,第二个参数是字符串的长度,第二个参数会取原字符串的指定长度作为查找的目标字符串。
版权声明
本文为[资深咸鱼~]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51644702/article/details/124242546
边栏推荐
- 保洁阿姨都能看懂的中国剩余定理和扩展中国剩余定理
- colab
- 1. View databases and tables
- Machine vision series (01) -- Overview
- Beifeng communication helps Zhanjiang fire brigade build PDT wireless communication system
- Discussion on arrow function of ES6
- 记录一个查询兼容性的网站,String.replaceAll()兼容性报错
- Pycharm
- [Educational Codeforces Round 80] 解题报告
- Lead the industry trend with intelligent production! American camera intelligent video production platform unveiled at 2021 world Ultra HD Video Industry Development Conference
猜你喜欢
随机推荐
使用el-popconfirm和el-backtop不生效
[牛客挑战赛47]C.条件 (bitset加速floyd)
[CF 1425D]Danger of Mad Snakes(组合计数+容斥)
推导式与正则式
ES6之箭头函数细谈
经典套路:一类字符串计数的DP问题
什么是闭包?
el-table 横向滚动条固定在可视窗口底部
keytool: command not found
USO technology was invited to share the technical framework and challenges of AI synthetic virtual characters at lvson2020 conference
[COCI]Lampice (二分+树分治+字符串哈希)
Dirichlet 前缀和(数论优化式子复杂度利器)
On BFC (block formatting context)
[牛客练习赛68]牛牛的粉丝(矩阵快速幂之循环矩阵优化)
ESP32学习-GPIO的使用与配置
1. View databases and tables
可视化常见绘图(四)柱状图
Applet newline character \ nfailure problem resolution - Daily pit stepping
理解补码的要点
UDP基础学习