Skip to content

keys() function

返回对象自身可枚举属性名的迭代器。

Signature:

typescript
declare function keys<T extends Record<string, any>>(
  obj: T,
): Generator<Extract<keyof T, string>, void, unknown>;

Example

ts
[...keys({ a: 1, b: "2", c: true })];
// ["a", "b", "c"]

Open Source Code

Released under the Apache-2.0 License.