Home  >  Article  >  Web Front-end  >  How to use endwith function

How to use endwith function

不言
不言Original
2019-02-18 16:47:589257browse

The endwith function is used to check whether the given string ends with the character of the specified string. The syntax of this function is "str.endsWith(searchString, length)".

How to use endwith function

The operating environment of this article: Windows 7 system, javascript version 1.8.5, Dell G3 computer.

The str.endsWith() function in JavaScript is used to check whether the given string ends with the character of the specified string. Let's take a closer look at how to use the endwith function.

Let’s first take a look at the basic syntax of the endsWith() function

str.endsWith(searchString,length)

The first parameter of the endsWith() function is the searchString string, which will be given in Search at the end of the string. The second parameter of the function is length, which determines the length of the given string starting from the search for searchString.

If searchString is found, this function returns a Boolean value true, otherwise it returns a Boolean value false

Let’s look at the specific example of the endsWith() function

The code is as follows

Check whether the string str ends with day.

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
    var str = &#39;It is a great day.&#39;; 
    var value = str.endsWith(&#39;day.&#39;);   
    document.write(value); 
} 
func(); 
</script>  
</body>
</html>

The output result is: true

Check whether the string str ends with great

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
    var str = &#39;It is a great day.&#39;; 
    var value = str.endsWith(&#39;great&#39;);   
    document.write(value); 
} 
func(); 
</script>  
</body>
</html>

The output result is: false

##Check whether the string str ends with great at the specified index 13

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
    var str = &#39;It is a great day.&#39;; 
    var value = str.endsWith(&#39;great&#39;,13);   
    document.write(value); 
} 
func(); 
</script>  
</body>
</html>

The output result is: true

This article ends here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use endwith function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn