endwith函数如何使用
发布时间:09/01 来源:未知 浏览:
关键词:
我们先来看一下endsWith()函数的根本语法
str.endsWith(searchString,length)
endsWith()函数的第一个参数是searchString字符串,它将在给定字符串的末尾停止搜索。函数的第二个参数是length,它肯定从搜索searchString开端的给定字符串的长度。
假如寻到searchString,则此函数返回布尔值true,不然返回布尔值false
下面我们来看endsWith()函数详细的示例
代码如下
检查字符串str可否以day.结尾
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> function func() { var str = 'It is a great day.'; var value = str.endsWith('day.'); document.write(value); } func(); </script> </body> </html>
输出结果为:true
检查字符串str可否以great结尾
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> function func() { var str = 'It is a great day.'; var value = str.endsWith('great'); document.write(value); } func(); </script> </body> </html>
输出结果为:false
检查字符串str可否在指定的索引13处以great结尾
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> function func() { var str = 'It is a great day.'; var value = str.endsWith('great',13); document.write(value); } func(); </script> </body> </html>
输出结果为:true
本篇文章到这里就全部完毕了,更多出色内容大家可以关注百分百源码网的其他相关栏目教程!!!
以上就是endwith函数如何使用的具体内容,更多请关注百分百源码网其它相关文章!