跳至主要內容

对象迭代

小于 1 分钟featurees-proposal

对象迭代open in new window

注意

该提案已被撤回,并将从下一个主要的 Core-JS 版本中删除。

模块

类型

class Object {
  iterateKeys(object: any): Iterator<string>;
  iterateValues(object: any): Iterator<any>;
  iterateEntries(object: any): Iterator<[string, any]>;
}

入口点

core-js/proposals/object-iteration
core-js(-pure)/full/object/iterate-keys
core-js(-pure)/full/object/iterate-values
core-js(-pure)/full/object/iterate-entries

示例

示例open in new window:

const obj = { foo: "bar", baz: "blah" };

for (const [key, value] of Object.iterateEntries(obj)) {
  console.log(`${key} -> ${value}`);
}

for (const key of Object.iterateKeys(obj)) {
  console.log(key);
}

for (const value of Object.iterateValues(obj)) {
  console.log(value);
}