Home > Article > Web Front-end > How to use endwith function
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)".
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 = 'It is a great day.'; var value = str.endsWith('day.'); 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 = 'It is a great day.'; var value = str.endsWith('great'); 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 = 'It is a great day.'; var value = str.endsWith('great',13); document.write(value); } func(); </script> </body> </html>The output result is: trueThis 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!