- 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
广告