method Enumerable.prototype.enum
Enumerable.prototype.enum(): Enumerable<[T, number]>

Adds a counter from 0 to n-1 of the items being enumerated.

Returns tuples of [item, index] where index starts at 0.

Examples

Add indices to items

import { enumerate } from "jsr:@j50n/proc";

const result = await enumerate(["a", "b", "c"])
  .enum()
  .collect();
// [["a", 0], ["b", 1], ["c", 2]]

Format with indices

import { enumerate } from "jsr:@j50n/proc";

const result = await enumerate(["apple", "banana"])
  .enum()
  .map(([item, i]) => `${i + 1}. ${item}`)
  .collect();
// ["1. apple", "2. banana"]

Return Type

Enumerable<[T, number]>

An Enumerable of [item, index] tuples.

Usage

import { Enumerable } from ".";