Prototype-enum-pluck

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

プロトタイプ-列挙可能なpluck()メソッド

このメソッドは、collect()メソッドの一般的なユースケースの最適化です。 すべての要素に対して同じプロパティを取得します。

構文

Iterator.pluck(propertyName);

戻り値

プロパティ値の配列を返します。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>

      <script>
         function showResult() {
            var arr = ['world', 'this', 'is', 'nice'].pluck('length');

            alert("Test 1 : " + arr.inspect() );
           //Returns [5, 4, 2, 4]
         }
      </script>
   </head>

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

出力