-
PIPIONE
我们已经建立了一个名为 Object 的全局类,它是原型链的起点,换句话说,它是原型中的最顶层节点。我们可以检查任何对象的键和值的值,例如-Object.keys(["a", "b", "c"]);// 输出[“0”、“1”、“2”]0: "0"1: "1"2: "2"length: 3值相同Object.values(["a", "b", "c"]);// 输出 ["a", "b", "c"]0: "a"1: "b"2: "c"length: 3
-
jeck猫
是的,您可以使用例如Object.entries来验证它,它返回对象的键值对:Object.entries(["a", "b", "c"])// Output0: (2) ["0", "a"]1: (2) ["1", "b"]2: (2) ["2", "c"]
-
慕田峪7331174
地图的另一种方式。有关更多信息,请参阅以下 URL。 https://javascript.info/keys-values-entrieshttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...ofconst iterable = new Map([['a', 1], ['b', 2], ['c', 3]]);for (const entry of iterable) { console.log(entry);}// ['a', 1]// ['b', 2]// ['c', 3]for (const [key, value] of iterable) { console.log(value);}