Skip to main content

keys()

Try it

keys() 方法返回一个包含数组中每个索引键的 Array Iterator 对象。

const array1 = ["a", "b", "c"];
const iterator = array1.keys();

for (const key of iterator) {
console.log(key);
}

// expected output: 0
// expected output: 1
// expected output: 2

语法

返回值

一个新的 Array 迭代器对象。