can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
37 lines (28 loc) • 833 B
Markdown
List.prototype.each each
can.List.prototype
can.List.prototype.each each
Call a function on each element of a List.
`list.each( callback(item, index) )`
`each` iterates through the List, calling a function
for each element.
{function(*, Number)} callback the function to call for each element
The value and index of each element will be passed as the first and second
arguments, respectively, to the callback. If the callback returns false,
the loop will stop.
{can.List} this List, for chaining
```
var i = 0;
new can.List([1, 10, 100]).each(function(element, index) {
i += element;
});
i; // 111
i = 0;
new can.List([1, 10, 100]).each(function(element, index) {
i += element;
if(index >= 1) {
return false;
}
});
i; // 11
```
can.