Object.getOwnPropertySymbols
Returns an array of all symbol properties found directly upon a given object
Syntax
Object.getOwnPropertySymbols(obj)Parameters
| Parameter | Type | Description |
|---|---|---|
| obj | object | The object whose symbol properties are to be returned |
Return Value
An array of symbols
Examples
const id = Symbol('id');
const obj = { [id]: 123, name: 'Alice' };
console.log(Object.getOwnPropertySymbols(obj)); // [Symbol(id)]const sym1 = Symbol('a');
const sym2 = Symbol('b');
const obj = { [sym1]: 1, [sym2]: 2, c: 3 };
const symbols = Object.getOwnPropertySymbols(obj);
console.log(symbols.length); // 2const obj = {};
console.log(Object.getOwnPropertySymbols(obj)); // []Understanding Object.getOwnPropertySymbols
The Object.getOwnPropertySymbols method in JavaScript returns an array of all symbol properties found directly upon a given object. It belongs to the Object object and is one of the most widely used methods for working with object values in modern JavaScript and TypeScript applications.
The method signature is Object.getOwnPropertySymbols(obj). It accepts 1 parameter: obj. When called, it returns an array of symbols. Understanding when and how to use getOwnPropertySymbols() helps you write more expressive, readable code.
Common use cases for Object.getOwnPropertySymbols include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like object-getownpropertynames, object-keys, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Object.getOwnPropertySymbols is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More Object Methods
Other methods in the Object object
Related Tools
More Object Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.