当前位置:网站首页>Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
2022-04-23 07:45:00 【Senior salted fish~】
startsWith(): Indicates whether the parameter string is in the of the original string Head , return Boolean value
endsWith(): Indicates whether the parameter string is in the of the original string The tail , return Boolean value
application :
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
From the example we can see :
1、 When a string calls endsWith() When the method does not pass parameters , The default is undefined The result is false;
2、 When looking for an empty string , The result is true, That's because empty characters exist in any string ;
3、 When there is a second parameter , The second parameter is the length of the string , The second parameter will take the specified length of the original string as the target string .
版权声明
本文为[Senior salted fish~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230623086845.html
边栏推荐
猜你喜欢

Date对象(js内置对象)

keytool: command not found

安装配置淘宝镜像npm(cnpm)

超级宝典&编程指南(红蓝宝书)-读书笔记

设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?

防抖和节流

Solutions to common problems in visualization (VII) solutions to drawing scale setting

如何判断点是否在多边形内(包含复杂多边形或者多边形数量很多的情况)

SAP PI/PO rfc2RESTful 发布rfc接口为RESTful示例(Proxy间接法)

如何SQL 语句UNION实现当一个表中的一列内容为空时则取另一个表的另一列
随机推荐
判断字符串首尾是否包含目标参数:startsWith()、endsWith()方法
SAP 导出Excel文件打开显示:“xxx“的文件格式和扩展名不匹配。文件可能已损坏或不安全。除非您信任其来源,否则请勿打开。是否仍要打开它?
快排的练习
keytool: command not found
手游的热更方案与动态更新策略
移动布局(flex布局、视口标签)
Methods of database query optimization
系统与软件安全研究(三)
Processing of common dependency module
2. Restricted query
SAP ECC连接SAP PI系统配置
js之排他思想及案例
6. Aggregation function and grouping statistics
数据分析入门 | kaggle泰坦尼克任务(三)—>探索数据分析
MySQL index
刨根问底---cocos2d源码的理解与分析
配置npm
【TED系列】一个习惯是如何改变我的一生
面经总结2
页面动态显示时间(升级版)