Skip to main content

Variable: index()

const index: <Value>(iterable) => Iterable<[number, Value]>

Defined in: transforms.d.ts:359

Returns an iterable equivalent to iterable except each value of iterable is placed in an entry containing the value's 0-based index in the iteration order followed by the value itself.

Type Parameters

Value

Value

Parameters

iterable

Iterable<Value>

Returns

Iterable<[number, Value]>

Example

console.log(
pipe(
[`sloth`, `more sloth`, `even more sloth`],
index,
reduce(toArray()),
),
)
//=> [ [ 0, 'sloth' ], [ 1, 'more sloth' ], [ 2, 'even more sloth' ] ]

Since

v2.0.0