Prototype - Enumerable include() 方法

此方法根据 == 比较运算符确定给定对象是否在 Enumerable 中。这是 member() 方法的别名。

如果您需要检查是否有与给定谓词匹配的元素,请改用 any() 方法。

语法

Iterator.include(object);

返回值

如果找到给定对象,则返回 true,否则返回 false。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            alert("$R(1,15).include(10) : " + $R(1,15).include(10) );
            // Returns true

            alert("['hello', 'world'] : " + $R(1,15).include('HELLO') );
            // Returns false
         }
      </script>
   </head>

   <body>
      <p>单击按钮查看结果。</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

输出

prototype_enumerating.html