- Prototype 教程
- Prototype - 主頁
- Prototype - 簡短概述
- Prototype - 有用功能
- Prototype - 實用方法
- Prototype - 元素物件
- Prototype - 數字處理
- Prototype - 字串處理
- Prototype - 陣列處理
- Prototype - 雜湊處理
- Prototype - 基本物件
- Prototype - 模板化
- Prototype - 列舉
- Prototype - 事件處理
- Prototype - 表單管理
- Prototype - JSON 支援
- Prototype - AJAX 支援
- Prototype - 表達範圍
- Prototype - 週期性執行
- Prototype 實用資源
- Prototype - 快速指南
- Prototype - 實用資源
- Prototype - 討論
Prototype - 可列舉的 inGroupsOf() 方法
此方法按固定大小塊對專案進行分組,必要時使用特定值填充最後一塊。
語法
Iterator.inGroupsOf(size[, filler = null]);
返回值
返回所有迭代器為 true 的元素。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var students = [
{ name: 'Sunny', age: 20 }, { name: 'Audrey', age: 21 },
{ name: 'Matt', age: 20 }, { name: 'Lodie', age: 26 },
{ name: 'Will', age: 21 }, { name: 'David', age: 23 },
{ name: 'Julien', age: 22 }, { name: 'Thomas', age: 21 },
{ name: 'Serpil', age: 22 }
];
alert ( students.pluck('name').inGroupsOf(4) ) ;
// Returns [ ['Sunny', 'Audrey', 'Matt', 'Lodie'],
// ['Will', 'David', 'Julien', 'Thomas'],
// ['Serpil', null, null, null] ]
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
輸出
prototype_enumerating.htm
廣告