close

Stage 3 Draft / May 29, 2026

Iterator Includes

1 Iterator.prototype.includes ( searchElement [ , skippedElements ] )

  1. Let O be the this value.
  2. If O is not an Object, throw a TypeError exception.
  3. Let iterated be the Iterator Record { [[Iterator]]: O, [[NextMethod]]: undefined, [[Done]]: false }.
  4. If skippedElements is undefined, then
    1. Let toSkip be +0𝔽.
  5. Else,
    1. If skippedElements is not one of +∞𝔽, -∞𝔽, or an integral Number, then
      1. Let error be ThrowCompletion(a newly created TypeError object).
      2. Return ? IteratorClose(iterated, error).
    2. Let toSkip be skippedElements.
  6. If toSkip < -0𝔽, then
    1. Let error be ThrowCompletion(a newly created RangeError object).
    2. Return ? IteratorClose(iterated, error).
  7. If toSkip is finite and toSkip > 𝔽(253 - 1), then
    1. Let error be ThrowCompletion(a newly created RangeError object).
    2. Return ? IteratorClose(iterated, error).
  8. Let skipped be +0𝔽.
  9. Set iterated to ? GetIteratorDirect(O).
  10. Repeat,
    1. Let value be ? IteratorStepValue(iterated).
    2. If value is done, return false.
    3. If skipped < toSkip, then
      1. Set skipped to skipped + 1𝔽.
    4. Else if SameValueZero(value, searchElement) is true, then
      1. Return ? IteratorClose(iterated, NormalCompletion(true)).