MDN will be in maintenance mode on Wednesday September 20th, starting at 10 AM Pacific / 5 PM UTC, for about 1 hour.

Object.getOwnPropertySymbols() 方法会返回一个数组,该数组包含了指定对象自身的(非继承的)所有 symbol 属性键。

语法

Object.getOwnPropertySymbols(obj)

参数

obj
任意一个对象

描述

该方法和 Object.getOwnPropertyNames() 类似,但后者返回的结果只会包含字符串类型的属性键,也就是传统的属性名

示例

var obj = {};
var a = Symbol("a");
var b = Symbol.for("b");

obj[a] = "localSymbol";
obj[b] = "globalSymbol";

var objectSymbols = Object.getOwnPropertySymbols(obj);

console.log(objectSymbols.length); // 2
console.log(objectSymbols)         // [Symbol(a), Symbol(b)]
console.log(objectSymbols[0])      // Symbol(a)

规范

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

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 38 36.0 (36.0) 未实现 25 9
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 5.1 38 36.0 (36.0) 未实现 25 9

相关链接

文档标签和贡献者

 此页面的贡献者: AlexChao, ziyunfei
 最后编辑者: AlexChao,