当前位置:首页 > 手册大全 > javascript手册 > Array.prototype.keys()

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

语法

arr.keys()

返回值 

一个新的 Array 迭代器对象。

示例

索引迭代器会包含那些没有对应元素的索引

var arr = ["a", , "c"];
var sparseKeys = Object.keys(arr);
var denseKeys = [...arr.keys()];
console.log(sparseKeys); // ['0', '2']
console.log(denseKeys);  // [0, 1, 2]

规范

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
Array.prototype.keys
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
Array.prototype.keys
Draft  

浏览器兼容性

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
Basic support Chrome Full support 38 Edge Full support Yes Firefox Full support 28 IE No support No Opera Full support 25 Safari Full support 8 WebView Android Full support Yes Chrome Android Full support Yes Edge Mobile Full support Yes Firefox Android Full support 28 Opera Android Full support Yes Safari iOS Full support 8 Samsung Internet Android Full support Yes nodejs Full support 0.12

Legend

Full support  
Full support
No support  
No support

相关链接

公益性全栈资源网站,鸣谢默默付出的博主、工程师、架构师们。
网站内容来源技术大牛的辛勤结晶。
81For 技术网站 Copyright ©2019 备案号:津ICP备19001147号-2