endswith方法
字符串endsWith()方法 (String endsWith() Method)
endsWith() method is a string method in JavaScript, it is used to check whether a string ends with a specified substring or not.
EndsWith()方法是JavaScript中的字符串方法,用于检查字符串是否以指定的子字符串结尾。
It returns true – if string ends with a specified substring, and it returns false – if string does not end with the specified substring.
它返回true -如果有一个指定的子字符串结尾,并返回false -如果字符串不与指定的字符串结束。
Syntax:
句法:
String.endsWith(substring);
Examples:
例子:
Input:
str = "IncludeHelp is made for students.";
substring = "students."
//function call
str.endsWith(substring);
Output:
True
Input:
str = "IncludeHelp is made for students.";
substring = "Bye"
//function call
str.endsWith(substring);
Output:
False
Code:
码:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var str = "IncludeHelp is made for students.";
var substring = "students.";
if(str.endsWith(substring)){
document.write(str + " ends with " + substring + "<br>");
}
else{
document.write(str + " does not end with " + substring + "<br>");
}
substring = "Bye";
if(str.endsWith(substring)){
document.write(str + " ends with " + substring + "<br>");
}
else{
document.write(str + " does not end with " + substring + "<br>");
}
</script>
</body>
</html>
Output
输出量
IncludeHelp is made for students. ends with students.
IncludeHelp is made for students. does not end with Bye
翻译自: https://www.includehelp.com/code-snippets/string-endsWith-method-with-example-in-javascript.aspx
endswith方法