JavaScript Object Methods

Every static Object method — signature, real examples that log output, and the shallow-vs-deep gotcha. ES2022+ (Object.hasOwn, groupBy).

Inspection

Object.keys
Returns an array of a given object's own enumerable string-keyed property names. The order matches a normal for...in loop but excludes inherited and non-enumerable properties.
Object.values
Returns an array of a given object's own enumerable string-keyed property values. Introduced in ES2017 as a companion to Object.keys.
Object.entries
Returns an array of a given object's own enumerable string-keyed [key, value] pairs. Useful for iterating objects with for...of destructuring or converting to a Map.
Object.hasOwn
Returns true if the specified object has the given property as its own property (not inherited). Added in ES2022 as the recommended replacement for Object.prototype.hasOwnProperty.
Object.prototype.hasOwnProperty
Instance method returning true if the object has the specified property as its own (non-inherited) property. Superseded by the safer static Object.hasOwn in ES2022.
Object.getOwnPropertyNames
Returns an array of all own string-keyed property names, including non-enumerable ones (but not Symbol keys). Useful for introspection where Object.keys is too restrictive.
Object.getOwnPropertyDescriptor
Returns the property descriptor for an own property on the given object, or undefined if the property does not exist. Descriptors describe writability, enumerability, configurability, and getters/setters.
Object.getPrototypeOf
Returns the prototype (i.e. the internal [[Prototype]]) of the specified object, or null if it has none. Preferred over the legacy __proto__ accessor.
Object.is
Determines whether two values are the same value using the SameValue algorithm. Similar to === but treats NaN as equal to NaN and distinguishes +0 from -0.

Creation & Assign

Mutation

Iteration

Protection (Freeze / Seal)

Related references