Standard built-ins

Iterator.prototype.flatMap()

Try the free JavaScript compiler

Lazily maps each value to an iterator or iterable object and yields its elements in sequence. Primitive strings are not accepted as mapped results.

Formal Syntax & Structure

javascript syntaxjavascript
iterator.flatMap(mapper)

Parameters & Attributes

NameTypeDescription
mapperfunctionCallback returning an iterable object or iterator.

Return Value

Iterator

Result of the operation.

Working Example

Example Snippetjavascript
console.log(JSON.stringify(Iterator.from([1,2]).flatMap(x=>[x,x]).toArray()));
JavaScript Reference