February 2018
Intermediate to advanced
298 pages
8h 22m
English
The Object.getOwnPropertyNames() method cannot retrieve the symbol properties. Therefore, ES6 introduced Object.getOwnPropertySymbols() to retrieve an array of symbol properties of an object. Here is an example to demonstrate this:
let obj = {a: 12};let s1 = Symbol("mySymbol");let s2 = Symbol("mySymbol");Object.defineProperty(obj, s1, {enumerable: false});obj[s2] = "";console.log(Object.getOwnPropertySymbols(obj));
The output is as follows:
Symbol(mySymbol),Symbol(mySymbol)
From the previous example, you can see that the Object.getOwnPropertySymbols() method can also retrieve the non-enumerable symbol properties.
Read now
Unlock full access