Skip to content
FLAVIO COPES
flaviocopes.com

The Object getOwnPropertySymbols() method

By

Learn how the JavaScript Object.getOwnPropertySymbols() method returns an array of the Symbol keys defined on an object, a companion to the ES2015 Symbol type.

~~~

Get an array of symbols defined on an object.

Symbols are an ES2015 feature, and this method was introduced in ES2015 as well.

Example:

const dog = {}
const r = Symbol('Roger')
const s = Symbol('Syd')
dog[r] = {
  name: 'Roger',
  age: 6
}
dog[s] = {
  name: 'Syd',
  age: 5
}

Object.getOwnPropertySymbols(dog) //[ Symbol(Roger), Symbol(Syd) ]
Tagged: JavaScript ยท All topics
~~~

Related posts about js: