当前位置:网站首页>判断字符串首尾是否包含目标参数: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
边栏推荐
- [hdu6833]A Very Easy Math Problem(莫比乌斯反演)
- Wireless communication system for large-scale sports events
- 按需引入vant组件
- Metro wireless intercom system
- Machine vision series (02) -- tensorflow2 3 + win10 + GPU installation
- 反思 | 事件总线的局限性,组件化开发流程中通信机制的设计与实现
- 获取字符格式的当前时间
- [CodeForces - 208E] Blood Cousins(k代兄弟问题)
- ES6之箭头函数细谈
- Typora语法详解(一)
猜你喜欢

可视化之路(九)Arrow类详解

可视化常见问题解决方案(八)数学公式

el-select 中v-model绑定值,数据回显只显示value,不显示label
![[COCI]Lampice (二分+树分治+字符串哈希)](/img/7b/fe2a45d960a6d3eb7dc25200304adc.png)
[COCI]Lampice (二分+树分治+字符串哈希)

vim+ctags+cscpope开发环境搭建指南

Solution of self Networking Wireless Communication intercom system in Beifeng oil and gas field

菜菜的刷题日记 | 238.除自身以外数组的乘积

Educational Codeforces Round 81 (Rated for Div. 2)

keytool: command not found

Typora语法详解(一)
随机推荐
按需引入vant组件
Solution of self Networking Wireless Communication intercom system in Beifeng oil and gas field
图论入门——建图
推导式与正则式
el-select 中v-model绑定值,数据回显只显示value,不显示label
Applet Wx Previewmedia related problem solving - Daily stepping on the pit
Take you to travel in space, and American photography technology provides comprehensive technical support for aerospace creative applet
MVCC(多版本并发控制)
[ACM-ICPC 2018 沈阳赛区网络预赛] J.Ka Chang (分块+dfs序)
数论分块(整除分块)
Flexible blind patch of ad hoc network | Beifeng oil and gas field survey solution
技能点挖坑
Transformer的pytorch实现
kaggle-房价预测实战
The people of Beifeng have been taking action
[Ted series] how to get along with inner critics?
14.事务处理
配置npm
可视化常见问题解决方案(八)数学公式
ESP32学习-向工程项目添加文件夹