pairs

function* pairs<T>(arr: T[]): IterableIterator<[number, T]

Returns an iterator that yields pairs of indices and values from an unsorted array.

const arr = ['a', 'b', 'c']
for (const [i, val] of Utils.pairs(arr)) {
   console.log(i, val); // i = index, val = value (val is from type string)
}
Parameter
Type
Optional
Description

arr

T[]

The array to iterate over

Last updated