JS Built-ins
ObjectObject.getOwnPropertySymbolsintermediate

Object.getOwnPropertySymbols() β€” returns Symbol keys

πŸ“– Usage Example
// Get all Symbol-keyed properties
const sym = Symbol('id')
const obj = { [sym]: 1, name: 'Alice' }
Object.getOwnPropertySymbols(obj)   // β†’ [Symbol(id)]

Use Object.getOwnPropertySymbols() to retrieve all symbol-keyed own properties, which are invisible to Object.keys().

Object.getOwnPropertySymbols()

Object.getOwnPropertySymbols(obj) returns an array of all own Symbol-keyed properties. Symbols are not returned by Object.keys or Object.getOwnPropertyNames.

Challenge: Implement getSymbolKeys(obj) that returns the Symbol-keyed properties of obj.

const s = Symbol('key')
getSymbolKeys({ [s]: 1 }) // β†’ [s]
πŸ’‘ Hints (1)
  • β€’ `Object.getOwnPropertySymbols` is the Symbol counterpart of `Object.getOwnPropertyNames`.