静态方法 Reflect.ownKeys() 返回一个由目标对象自身的属性键组成的数组。

语法

Reflect.ownKeys(target)

参数

target
获取自身属性键的目标对象。

返回值

由目标对象的自身属性键组成的 Array。 

异常

如果目标不是 Object,抛出一个 TypeError

描述

Reflect.ownKeys 方法返回一个由目标对象自身的属性键组成的数组。它的返回值等同于Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target))。

示例

使用 Reflect.ownKeys()

Reflect.ownKeys({z: 3, y: 2, x: 1}); // [ "z", "y", "x" ]
Reflect.ownKeys([]); // ["length"]

var sym = Symbol.for("comet");
var sym2 = Symbol.for("meteor");
var obj = {[sym]: 0, "str": 0, "773": 0, "0": 0,
           [sym2]: 0, "-1": 0, "8": 0, "second str": 0};
Reflect.ownKeys(obj);
// [ "0", "8", "773", "str", "-1", "second str", Symbol(comet), Symbol(meteor) ]
// Indexes in numeric order, 
// strings in insertion order, 
// symbols in insertion order

规范

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

浏览器兼容

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support 49Edge Full support 12Firefox Full support 42IE No support NoOpera Full support 36Safari Full support 10WebView Android Full support 49Chrome Android Full support 49Edge Mobile Full support YesFirefox Android Full support 42Opera Android Full support 36Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0

Legend

Full support  
Full support
No support  
No support

相关链接

文档标签和贡献者

标签: 
此页面的贡献者: zhangchen, liuy1994, Hushabyme
最后编辑者: zhangchen,