Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

Prototype Enumerable zip() Method


previous next AddThis Social Bookmark Button


Advertisements

This method zips together 2 + sequences, providing an array of tuples.

Each tuple contains one value per original sequence. Tuples can be converted to something else by applying the optional iterator on them.

Syntax:

Iterator.zip(Sequence);

Return Value :

  • Returns an array of zipped values

Example:

<html>
<head>
<title>Prototype examples</title>
<script type="text/javascript" 
   src="/javascript/prototype.js">
</script>

<script>

function showResult(){
  var firstNames = ['Justin', 'Tobie', 'Christophe'];
  var lastNames = ['Palmer', 'Langel', 'Porteneuve'];
  var zipped = firstNames.zip(lastNames);

  alert("zipped values: " + zipped.inspect());

  var zipped = firstNames.zip(lastNames, function(a)
                            { 
			      return a.join(' '); 
			    })
  alert("zipped values: " + zipped.inspect());
}

</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 Printer Friendly

Advertisements


  

Advertisements