您好,欢迎访问一九零五行业门户网

endwith函数怎么使用

endwith函数用于检查给定的字符串是否以指定字符串的字符结尾,该函数的使用语法是“str.endswith(searchstring,length)”。
本文操作环境:windows7系统、javascript1.8.5版、dell g3电脑。
javascript中的str.endswith()函数用于检查给定的字符串是否以指定字符串的字符结尾。下面我们就来具体看看endwith函数的使用方法。
我们先来看一下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函数怎么使用的详细内容。
其它类似信息

推荐信息