返回到:Prototype – 枚举
此方法将项目分组为固定大小的块,必要时使用特定值填充最后一个块。
语法
Iterator.inGroupsOf(size[, filler = null]);
返回值
返回迭代器返回 true 的所有元素。
例子
HTML
x
30
30
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
var students = [
9
{ name: 'Sunny', age: 20 }, { name: 'Audrey', age: 21 },
10
{ name: 'Matt', age: 20 }, { name: 'Lodie', age: 26 },
11
{ name: 'Will', age: 21 }, { name: 'David', age: 23 },
12
{ name: 'Julien', age: 22 }, { name: 'Thomas', age: 21 },
13
{ name: 'Serpil', age: 22 }
14
];
15
16
alert ( students.pluck('name').inGroupsOf(4) ) ;
17
// Returns [ ['Sunny', 'Audrey', 'Matt', 'Lodie'],
18
// ['Will', 'David', 'Julien', 'Thomas'],
19
// ['Serpil', null, null, null] ]
20
}
21
</script>
22
</head>
23
24
<body>
25
<p>Click the button to see the result.</p>
26
<br />
27
<br />
28
<input type = "button" value = "Result" onclick = "showResult();"/>
29
</body>
30
</html>
返回到:Prototype – 枚举
阅读剩余 44%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8614.html