TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Javascript Object getOwnPropertySymbols() Method

Javascript Object getOwnPropertySymbols() Method with example on javascript, object, getOwnPropertySymbols(), getPrototypeOf(), defineProperties(), defineProperty(), entries(), freeze(), javascript tutorial, javascript array etc.

<< Back to JAVASCRIPT

JavaScript Object.getOwnPropertySymbols() Method

The 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:

Chrome 38
Edge Yes
Firefox 36
Opera 35

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




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf