- Prototype - Home
- Prototype - Short Overview
- Prototype - Useful Features
- Prototype - Utility Methods
- Prototype - Element Object
- Prototype - Number Processing
- Prototype - Strings Processing
- Prototype - Array Processing
- Prototype - Hash processing
- Prototype - Basic Object
- Prototype - Templating
- Prototype - Enumerating
- Prototype - Event Handling
- Prototype - Form Management
- Prototype - JSON Support
- Prototype - AJAX Support
- Prototype - Expressing Ranges
- Prototype - Periodical Execution
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
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>
Output
prototype_enumerating.htm
Advertisements