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:

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:

<!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