Function enumerate

  • Yields elements like [index, item] from an iterable. Index starts at zero by default.

    Returns

    A generator with tuples like [index, item].

    Example

    console.log([...enumerate(['hello', 'world'])])
    // [[0, 'hello'], [1, 'world']]

    // Start with index `1`
    console.log([...enumerate(['hello', 'world'], 1)])
    // [[1, 'hello'], [2, 'world']]

    Type Parameters

    • T

    Parameters

    • iterable: Iterable<T>

      The iterable to inspect.

    • start: number = 0

      The starting index.

    Returns Generator<[number, T], void, unknown>

Generated using TypeDoc