each
优质
小牛编辑
138浏览
2023-12-01
Iterates over this sequence and executes a function for every element.
Signature
Sequence.each = function(fn) { /*...*/ }
Sequence.each = function each(fn) { var iterator = this.getIterator(), i = -1; while (iterator.moveNext()) { if (fn(iterator.current(), ++i) === false) { return false; } } return true; }
Name | Type(s) | Description |
---|---|---|
fn | Function | The function to call on each element in the sequence. Return false from the function to end the iteration. |
returns | boolean |
|
Examples
Lazy([1, 2, 3, 4]).each(fn) // calls fn 4 times