当前位置:网站首页>判断字符串首尾是否包含目标参数: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
边栏推荐
猜你喜欢

Discussion on the outline of short video technology

浅谈BFC(块格式化上下文)

Machine vision series (02) -- tensorflow2 3 + win10 + GPU installation

记录一些npm 有关的问题(杂乱记录)

反思|开启B站少女心模式,探究APP换肤机制的设计与实现

可视化之路(十一)matplotlib颜色详解

数据分析入门 | kaggle泰坦尼克任务(四)—>数据清洗及特征处理

保洁阿姨都能看懂的中国剩余定理和扩展中国剩余定理

Nacos/sentinel网关限流和分组 (代码)

安装配置淘宝镜像npm(cnpm)
随机推荐
Meishe technology launches professional video editing solution for desktop -- Meiying PC version
浅谈BFC(块格式化上下文)
11.表和库的管理
[COCI]Lampice (二分+树分治+字符串哈希)
安装tui-editor失败,快速解决方案
# 可视化常见绘图(二)折线图
How does the public and Private Integrated walkie talkie realize cooperative work under multi-mode communication?
反思|开启B站少女心模式,探究APP换肤机制的设计与实现
AuthorizationServer(授权服务器的简单搭建)
Lead the industry trend with intelligent production! American camera intelligent video production platform unveiled at 2021 world Ultra HD Video Industry Development Conference
Source Insight 4.0常见问题
ESP32学习-向工程项目添加文件夹
LATEX使用
Applet newline character \ nfailure problem resolution - Daily pit stepping
组合数求解与(扩展)卢卡斯定理
13.用户和权限管理
Dirichlet 前缀和(数论优化式子复杂度利器)
可视化常见绘图(四)柱状图
可视化之路(十)分割画布函数详解
On BFC (block formatting context)