Learn Prototype
Prototype Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Prototype Enumerable zip() Method
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:
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.
|
|
|