Skip to main content
πŸ§™β€β™‚οΈ Kris Kowal 🐘 πŸ™ πŸ§› πŸ“Œ πŸ“¬

How do I enumerate thee? Let me count the ways.

Why only string-named own enumerable data properties? JavaScript has a tremendous number of different constructs for enumerating the properties of an object, with different semantics of what subset they choose to enumerate:
β€” @erights

I have largely duplicated Mark Miller’s table for my own reference, and now yours:

Operation P NE STR SYM output
for (... in ...) P STR k*
Object.keys STR [k*]
Object.values STR [v*]
Object.entries STR [[k,v]*]
{...obj} STR SYM {k:v*}
Object.assign STR SYM {k:v*}
Reflect.ownKeys NE STR SYM [k*]
Object.getOwnPropertyNames NE STR [k*]
Object.getOwnPropertySymbols NE SYM [k*]
Object.getOwnPropertyDescriptors NE STR SYM {k:d*}

Legend:

For objects with accessor properties (getters), JavaScript has two modes of copying, copy-by-value and copy-by-descriptor.