Skip to main content

Variable: keys()

const keys: {<Key>(object): Iterable<Key>; <Key>(object): Iterable<Key>; }

Defined in: generators.d.ts:56

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.

Call Signature​

<Key>(object): Iterable<Key>

Type Parameters​

Key​

Key

Parameters​

object​

ReadonlyMap<Key, unknown>

Returns​

Iterable<Key>

Call Signature​

<Key>(object): Iterable<Key>

Type Parameters​

Key​

Key extends PropertyKey

Parameters​

object​

Readonly<Record<Key, unknown>>

Returns​

Iterable<Key>

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