js endswith
js中endswith是什么呢?不知道的小伙伴来看看小编今天的分享吧!
1、js中endswit简介
endsWith()方法用来判断当前字符串是否是以一个给定的子字符串“结尾”的,根据判断结果返回 true 或 false。
The source for this interactive example is stored in a GitHub repository. If you’d like to contribute to the interactive examples project, please clone https://github./mdn/interactive-examples and send us a pull request.
Syntaxstr.endsWith(searchString[, length])
2、参数
searchString
要搜索的子字符串。
length
可选。作为 str 的长度。默认值为 str.length。
返回值
如果传入的子字符串在搜索字符串的末尾则返回true;否则将返回 false。
描述
这个方法帮助你确定一个字符串是否在另一个字符串的末尾。这个方法是大小写敏感的。
示例
使用 endsWith()var str = "To be, or not to be, that is the question.";
alert( str.endsWith("question.") ); // true
alert( str.endsWith("to be") ); // false
alert( str.endsWith("to be", 19) ); // true
Polyfill
这个方法已经加入到 ECMAScript 6 标准当中,可能还没有在所有的 JavaScript 实现中可用。,你可以通过如下的代码片段扩展 String.prototype.endsWith() 实现兼容if (!String.prototype.endsWith) {undefined
String.prototype.endsWith = function(search, this_len) {undefined
if (this_len === undefined || this_len > this.length) {undefined
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
};
}
以上就是小编今天的分享了,希望可以帮助到大家。
长沙网络推广
- 平凉整站优化:提升网站竞争力的关键
- 重庆百度关键词seo怎么做网络推广
- 松原关键词优化策略:提升您网站的可见性和流
- 万国数据备案域名出售:如何为您的业务选择合
- 兰州百度SEO排名:提升网站可见性的有效策略
- 山东优化关键词排名推广如何做百度排名
- 湟中百度优化服务:提升您网站排名的最佳选择
- 马关百度关键词SEO策略与实践指南
- 陕西SEO怎么做网站推广
- 花莲SEO优化:提升您网站排名的最佳策略
- 璧山SEO网站推广:有效提升你的网站流量与曝光
- 桂林优化关键词排名推广:提升您的在线能见度
- 崇信企业网站优化:提升您在线业务的秘密武器
- 江西SEO推广怎样跟客户谈判容易签下合同
- 为什么新网备案域名玩得开心?
- 开远百度关键词排名:提升你的网站可见度