Object Creation
- Object Literals:
{ key: value }
- Constructor:
new Object()
Object.create(proto, properties?)
→ Creates an object with a specified prototype.
Object.assign(target, ...sources)
→ Copies properties from source objects to the target object.
Object Structure & Properties
Object.keys(obj)
→ Returns an array of an object's keys.
Object.values(obj)
→ Returns an array of an object's values.
Object.entries(obj)
→ Returns an array of [key, value]
pairs.
Object.hasOwn(obj, key)
(ES2022+) → Safer alternative to .hasOwnProperty()
.
Object.hasOwnProperty(key)
→ Checks if an object has a direct property (not inherited).
Object.propertyIsEnumerable(key)
→ Checks if a property is enumerable.
Object.getOwnPropertyNames(obj)
→ Returns all property names, including non-enumerable.
Object.getOwnPropertySymbols(obj)
→ Returns symbol properties.
Prototype & Inheritance
Object.getPrototypeOf(obj)
→ Returns the prototype of an object.
Object.setPrototypeOf(obj, prototype)
→ Sets the prototype of an object.
__proto__
(Deprecated) → Directly modifies an object's prototype (use Object.getPrototypeOf()
instead).
Property Descriptors & Attributes
Object.defineProperty(obj, key, descriptor)
→ Defines or modifies a property with descriptors.