Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Object.getOwnPropertySymbols — own symbol keys

Object.getOwnPropertySymbols(obj) returns an array of Symbol keys. For ordinary objects, these are the keys of own properties, including non-enumerable ones. The method excludes string keys and does not traverse the prototype chain.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Object.getOwnPropertySymbols(obj)

Object.getOwnPropertySymbols(obj) is a static Object method that creates a new array containing only the Symbol keys from the list returned by the object's internal [[OwnPropertyKeys]] operation. It returns keys, not values or symbol descriptions. Read a property's value with obj[key].

The method excludes string keys and does not traverse the prototype chain. It does not check property descriptors: a Proxy with an extensible target can report a symbol through its ownKeys trap even if the proxy has no own property descriptor for that symbol.

For ordinary objects, the result includes keys of both enumerable and non-enumerable own properties, and symbols appear in the order those properties were created. Object.keys(obj) returns only enumerable own string keys, Object.getOwnPropertyNames(obj) returns all own string keys, and Reflect.ownKeys(obj) returns both kinds of own keys.

The argument is converted to an object; null and undefined cause a TypeError. Symbols do not provide privacy: this method can discover those keys even when enumerable: false.

In the example, the result contains visible and hidden, but neither inherited nor name. The comparisons check symbol identity, and the final line reads the values of the corresponding properties.

Examples

const inherited = Symbol('inherited');
const visible = Symbol('visible');
const hidden = Symbol('hidden');

const obj = Object.create({ [inherited]: 10 });
obj.name = 'demo';
obj[visible] = 20;
Object.defineProperty(obj, hidden, {
  value: 30,
  enumerable: false
});

const keys = Object.getOwnPropertySymbols(obj);
console.log(keys.length);
console.log(keys[0] === visible, keys[1] === hidden);
console.log(keys.includes(inherited));
console.log(keys.map(key => obj[key]).join(','));

Result

2
true true
false
20,30

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources