Standard built-ins

Iterator.prototype.take()

Try the free JavaScript compiler

Lazily produces at most the specified number of values. The limit is converted to Number and then truncated to an integer (or Infinity); NaN or a negative resulting integer throws RangeError.

Formal Syntax & Structure

javascript syntaxjavascript
iterator.take(limit)

Parameters & Attributes

NameTypeDescription
limitnumberNonnegative limit; converted to integer or Infinity.

Return Value

Iterator

Result of the operation.

Working Example

Example Snippetjavascript
console.log(JSON.stringify(Iterator.from([1,2,3]).take(2).toArray()));
JavaScript Reference