Prototype - Enumerable pluck() 方法
此方法是对 collect() 方法常见用例的优化。为所有元素获取相同的属性。
语法
Iterator.pluck(propertyName);
此方法是对 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>单击按钮查看结果。</p> <br /> <br /> <input type = "button" value = "Result" onclick = "showResult();"/> </body> </html>
如果您发现内容有误或提出修改建议,请随时向我们发送 E-mail 邮件:
421660149@qq.com
您的建议已发送到 W3schools。