Skip to main content

Function: keys()

Returns an iterable containing the keys of object.

This differs from Map.prototype.keys in that the returned iterable can be iterated multiple times and differs from Object.keys in that the returned iterable is opaque.

Example

import { keys, pipe, reduce, toArray } from 'lfi'

console.log(
pipe(
keys([`sloth`, `lazy`, `sleep`]),
reduce(toArray()),
),
)
//=> [ 0, 1, 2 ]

console.log(
pipe(
keys({
sloth: 1,
lazy: 2,
sleep: 3,
}),
reduce(toArray()),
),
)
//=> [ 'sloth', 'lazy', 'sleep' ]

console.log(
pipe(
keys(
new Map([
[`sloth`, 1],
[`lazy`, 2],
[`sleep`, 3],
]),
),
reduce(toArray()),
),
)
//=> [ 'sloth', 'lazy', 'sleep' ]
Playground

Since

v0.1.0

Call Signature

keys<Key>(object): Iterable<Key, any, any>

Type Parameters

Key

Parameters

object

ReadonlyMap<Key, unknown>

Returns

Iterable<Key, any, any>

Defined in

generators.d.ts:57

Call Signature

keys<Key>(object): Iterable<Key, any, any>

Type Parameters

Key extends PropertyKey

Parameters

object

Readonly<Record<Key, unknown>>

Returns

Iterable<Key, any, any>

Defined in

generators.d.ts:58