當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
字符串startswith_JavaScript字符串startsWith()方法与示例
生活随笔
收集整理的這篇文章主要介紹了
字符串startswith_JavaScript字符串startsWith()方法与示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
字符串startswith
字符串startsWith()方法 (String startsWith() Method)
startsWith() method is a string method in JavaScript, it is used to check whether a string starts with a specified substring or not.
startsWith()方法是JavaScript中的字符串方法,用于檢查字符串是否以指定的子字符串開頭。
It returns true – if string starts with a specified substring, and it returns false – if string does not start with the specified substring.
它返回true -如果字符串以指定的子,它返回false -如果字符串不與指定的字符串開始。
Syntax:
句法:
String.startsWith(substring);Examples:
例子:
Input:str = "IncludeHelp is made for students.";substring = "IncludeHelp"//function callstr.startsWith(substring);Output:TrueInput:str = "IncludeHelp is made for students.";substring = "Hello"//function callstr.startsWith(substring);Output:FalseCode:
碼:
<html> <head> <title>JavaScipt Example</title> </head><body> <script>var str = "IncludeHelp is made for students.";var substring = "IncludeHelp"; if(str.startsWith(substring)){document.write(str + " starts with " + substring + "<br>");}else{document.write(str + " does not start with " + substring + "<br>");}substring = "Hello";if(str.startsWith(substring)){document.write(str + " starts with " + substring + "<br>");}else{document.write(str + " does not start with " + substring + "<br>");} </script> </body> </html>Output
輸出量
IncludeHelp is made for students. starts with IncludeHelp IncludeHelp is made for students. does not start with Hello翻譯自: https://www.includehelp.com/code-snippets/string-startsWith-method-with-example-in-javascript.aspx
字符串startswith
總結
以上是生活随笔為你收集整理的字符串startswith_JavaScript字符串startsWith()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 仓库锁什么时候全区都能用?
- 下一篇: 颐和园最佳游览时间