Skip to main

fromArray

fromArray

Signature - source.ts#L653

function fromArray<T>(array: ArrayLike<T>): Source<T>

Creates a Source from the given array/array-like. The values of the array will be synchronously emitted by the created source upon each subscription.

Parameters

ParameterTypeDescription
array
ArrayLike<T>

The array/array-like to iterate over.

Returns

TypeDescription
Source<T>

The created source.

Example Usage

pipe(fromArray([1, 2, 3, 4]), subscribe(Sink(console.log)));
// Logs:
// Push(1), Push(2), Push(3), Push(4)
// End

Example Usage

pipe(
    fromArray({ length: 5, 0: 'foo', 3: 'bar' }),
    subscribe(Sink(console.log))
)
// Logs:
// Push('foo'), Push(undefined), Push(undefined), Push('bar'),
// Push(undefined)
// End

See Also