C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Object.getOwnPropertySymbols() MethodThe Object.getOwnPropertySymbols() method returns an array of all symbol properties found directly upon a given object. This method returns an empty array unless you have set symbol properties on your object. Syntax:
Object.getOwnPropertySymbols(obj) Parameter
obj: It is an object whose symbol properties are to be returned. Return value:
This method returns an array of all symbol properties found directly upon the given object. Browser Support:
Example 1
const object1 = {};
a = Symbol('a');
b = Symbol.for('b');
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);
Output: 0 Example 2
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: 2 Example 3
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: 2
Next TopicJavaScript Objects
|