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
Object.create
Creates a new object with the specified prototype and optional property descriptors. Pass null to create an object with no prototype at all.
Object.fromEntries
Transforms a list of key-value pairs into an object — the inverse of Object.entries. Introduced in ES2019 and accepts any iterable of [key, value] pairs, including Map.
Object.assign
Copies all enumerable own properties from one or more source objects to a target object, then returns the modified target. Performs a shallow merge, invoking source getters and target setters.
Object.defineProperty
Defines a new property directly on an object, or modifies an existing one, with fine-grained control over its descriptor. Returns the object.
Object.defineProperties
Defines multiple new or modified properties on an object by supplying a descriptors map. The batch-form counterpart of Object.defineProperty.
Mutation
Iteration
Protection (Freeze / Seal)
Object.freeze
Freezes an object: new properties cannot be added, existing properties cannot be removed, and their values, writability, and configurability cannot be changed. Returns the same object.
Object.isFrozen
Returns true if the object is frozen — non-extensible, and every own property is non-configurable and (if a data property) non-writable. Primitives are considered frozen.
Object.seal
Seals an object: prevents new properties from being added and marks all existing properties as non-configurable. Existing writable properties can still be reassigned.
Object.isSealed
Returns true if the object is sealed — non-extensible and all own properties are non-configurable. Frozen objects are always sealed; primitives are considered sealed.
Object.preventExtensions
Prevents new properties from being added to an object, but existing properties can still be modified, deleted, or reconfigured. The weakest of the three protection levels.
Object.isExtensible
Returns true if new properties can be added to the object. Sealed, frozen, and preventExtensions'd objects all return false; primitives always return false.