Prototype-string-endswith

提供:Dev Guides
移動先:案内検索

プロトタイプ-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>

出力