Prototype - endsWith() 方法



此方法檢查字串是否以子字串結尾。

語法

string.endsWith( substring );

返回值

返回一個布林值。如果字串以子字串結尾,則返回 true,否則返回 false。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var str = 'slaughter';
            alert("First Check : " + str.endsWith("ghter") );
            alert("Second Check : " + str.endsWith("TATA") );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

輸出

prototype_string_processing.htm
廣告
© . All rights reserved.