Object.getOwnPropertySymbols() JavaScript JS

The Javascript Object getOwnPropertySymbols() method retrieves an array of all its own symbol key properties. It will return an empty array if no symbol property is directly associated with an object.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Object.getOwnPropertySymbols(object)
Object.getOwnPropertySymbols(object)
Object.getOwnPropertySymbols(object)

Parameters:
object: It represents the object whose symbol properties have to be fetched.

Return:
An array of all own symbol key properties.

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
const obj = {};
x = Symbol('alpha');
y = Symbol.for('beta');
obj[x] = 'HELLO';
obj[y] = 'WORLD';
const objSymbols = Object.getOwnPropertySymbols(obj);
document.write(objSymbols.length);
</script>
</body>
</html
<!DOCTYPE html> <html> <body> <script> const obj = {}; x = Symbol('alpha'); y = Symbol.for('beta'); obj[x] = 'HELLO'; obj[y] = 'WORLD'; const objSymbols = Object.getOwnPropertySymbols(obj); document.write(objSymbols.length); </script> </body> </html
<!DOCTYPE html>
<html>
<body>
<script>
const obj = {};
x = Symbol('alpha');
y = Symbol.for('beta');
obj[x] = 'HELLO';
obj[y] = 'WORLD';
const objSymbols = Object.getOwnPropertySymbols(obj);
document.write(objSymbols.length);
</script>
</body>
</html