getOwnPropertySymbols() method

The Object.getOwnPropertySymbols function produces an array containing all symbol properties that are directly associated with a specified object. If there are no symbol properties defined on your object, this method will yield an empty array.

Syntax:

Example

Object.getOwnPropertySymbols(obj)

Parameter

obj : This refers to an object from which the symbol attributes are intended to be retrieved.

Return value:

This function provides an array containing all symbol properties that are directly associated with the specified object.

Browser Support:

Chrome 38
Edge Yes
Firefox 36
Opera 35

Example 1

Example

const object1 = {};
 a = Symbol('a');
 b = Symbol.for('b');
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);

Output:

Example 2

Example

const object1 = {};
 a = Symbol('a');
 b = Symbol.for('b');
object1[a] = 'Carry';
object1[b] = 'Marry';
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);

Output:

Example 3

Example

const object1 = {};
const a = Symbol('a');
const b = Symbol.for('b');
object1[a] = 'localSymbol';
object1[b] = 'globalSymbol';
const object2 = {};
const c = Symbol('c');
object2[c] = 'Carry';
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);

Output:

Input Required

This code uses input(). Please provide values below: