当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

each

优质
小牛编辑
127浏览
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;
}
NameType(s)Description
fnFunction

The function to call on each element in the sequence. Return false from the function to end the iteration.

returnsboolean

true if the iteration evaluated the entire sequence, or false if iteration was ended early.

Examples

Lazy([1, 2, 3, 4]).each(fn) // calls fn 4 times