Copyright © tutorialspoint.com

Prototype Enumerable inGroupsOf() Method

previous next


Advertisements

This method groups items in fixed-size chunks, using a specific value to fill up the last chunk if necessary.

Syntax:

Iterator.inGroupsOf(size[, filler = null]);

Return Value :

Example:

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

To understand it in better way you can Try it yourself.


previous next

Copyright © tutorialspoint.com