JavaScript Object Methods Reference
Browse, search, and run all JS Object static and prototype methods — with mutating badges, return types, ES version info, and live interactive examples
Showing 29 of 29 methods
Object.keys()StaticEnumerationNon-mutatingES5Returns an array of a given object's own enumerable string-keyed property names, in the same order as a for...in loop. Only own (not inherited) properties are included.
Object.keys(obj)→ string[]Params: obj — The object whose own enumerable string-keyed property names are to be returned.
Object.values()StaticEnumerationNon-mutatingES2017Returns an array of a given object's own enumerable string-keyed property values, in the same order as Object.keys(). Complements Object.keys() by returning values instead of keys.
Object.values(obj)→ any[]Params: obj — The object whose own enumerable string-keyed property values are to be returned.
Object.entries()StaticEnumerationNon-mutatingES2017Returns an array of a given object's own enumerable string-keyed [key, value] pairs. The direct counterpart to Object.fromEntries(). Ideal for iterating over an object with both key and value.
Object.entries(obj)→ [string, any][]Params: obj — The object whose own enumerable string-keyed [key, value] pairs are to be returned.
Object.fromEntries()StaticEnumerationNon-mutatingES2019Transforms a list of [key, value] pairs into an object. The counterpart to Object.entries(). Accepts any iterable of [key, value] pairs, including Map and arrays.
Object.fromEntries(iterable)→ objectParams: iterable — An iterable such as a Map or an array of [key, value] pairs.
Object.assign()StaticCompositionMutates objectES2015Copies all enumerable own properties from one or more source objects to the target object and returns the mutated target. Properties in later sources overwrite earlier ones. Use spread {...a, ...b} for a non-mutating alternative.
Object.assign(target, ...sources)→ object (target, same reference)Params: target — The target object to copy properties into; sources — One or more source objects to copy from.
Object.create()StaticCompositionNon-mutatingES5Creates a new object with the specified prototype. The primary use-case is prototype-based inheritance without class syntax. Pass null to create an object with no prototype (a pure dictionary with no inherited methods).
Object.create(proto, propertiesObject?)→ objectParams: proto — The prototype for the new object (or null for no prototype); propertiesObject — Optional property descriptors to define on the new object.
Object.groupBy()StaticCompositionNon-mutatingES2024Groups elements of a given iterable according to the string key returned by a callback function. Returns a null-prototype object where each key is a group name and each value is an array of elements. For Map-keyed groups, use Map.groupBy().
Object.groupBy(iterable, callbackFn)→ { [key: string]: T[] }Params: iterable — An iterable (Array, Set, etc.) to group; callbackFn — A function that returns the group key for each element.
Object.defineProperty()StaticPropertyMutates objectES5Defines a new property on an object or modifies an existing one using a property descriptor. Allows fine-grained control over enumerability, writability, and configurability — attributes that cannot be set with simple assignment.
Object.defineProperty(obj, prop, descriptor)→ object (same reference)Params: obj — The object to define the property on; prop — The property name or Symbol; descriptor — A property descriptor (data or accessor).
Object.defineProperties()StaticPropertyMutates objectES5Defines multiple own properties on an object simultaneously using property descriptors. Equivalent to calling Object.defineProperty() multiple times but more concise and efficient.
Object.defineProperties(obj, props)→ object (same reference)Params: obj — The object to define properties on; props — An object whose keys are property names and values are property descriptors.
Object.getOwnPropertyDescriptor()StaticPropertyNon-mutatingES5Returns a property descriptor for an own property of the given object, or undefined if the property does not exist. Reveals the hidden attributes: value, writable, get, set, enumerable, and configurable.
Object.getOwnPropertyDescriptor(obj, prop)→ PropertyDescriptor | undefinedParams: obj — The object to inspect; prop — The name of the property whose descriptor is to be retrieved.
Object.getOwnPropertyDescriptors()StaticPropertyNon-mutatingES2017Returns all own property descriptors of an object. Unlike Object.assign(), using this with Object.create() or Object.defineProperties() correctly copies getters and setters (instead of calling them).
Object.getOwnPropertyDescriptors(obj)→ Record<string, PropertyDescriptor>Params: obj — The object whose own property descriptors are to be returned.
Object.getOwnPropertyNames()StaticPropertyNon-mutatingES5Returns an array of all own property names including non-enumerable ones, but excluding Symbol-keyed properties. Unlike Object.keys(), this includes properties defined with enumerable: false.
Object.getOwnPropertyNames(obj)→ string[]Params: obj — The object whose own property names are to be returned.
Object.getOwnPropertySymbols()StaticPropertyNon-mutatingES2015Returns an array of all own Symbol-keyed properties. Since Symbols are invisible to Object.keys() and for...in loops, this is the only way to enumerate Symbol-keyed own properties.
Object.getOwnPropertySymbols(obj)→ symbol[]Params: obj — The object whose own Symbol-keyed properties are to be returned.
Object.freeze()StaticIntegrityMutates objectES5Freezes an object: prevents new properties from being added, existing properties from being removed, and existing property values from being changed. Shallow — nested objects remain mutable. Returns the same object reference.
Object.freeze(obj)→ object (same reference, now frozen)Params: obj — The object to freeze.
Object.isFrozen()StaticIntegrityNon-mutatingES5Returns true if the object is frozen — no properties can be added, removed, or changed. An empty non-extensible object is also considered frozen. Primitive values are always frozen.
Object.isFrozen(obj)→ booleanParams: obj — The object to check.
Object.seal()StaticIntegrityMutates objectES5Seals an object: prevents new properties from being added and marks all existing properties as non-configurable. Unlike freeze(), existing writable properties can still have their values changed. Returns the same object reference.
Object.seal(obj)→ object (same reference, now sealed)Params: obj — The object to seal.
Object.isSealed()StaticIntegrityNon-mutatingES5Returns true if the object is sealed — no new properties can be added and all existing properties are non-configurable. A frozen object is always also sealed.
Object.isSealed(obj)→ booleanParams: obj — The object to check.
Object.preventExtensions()StaticIntegrityMutates objectES5Prevents new properties from being added to the object. Existing properties can still be deleted or modified. Less restrictive than seal() (which also prevents deletion) or freeze() (which also prevents value changes). Returns the same object reference.
Object.preventExtensions(obj)→ object (same reference)Params: obj — The object to make non-extensible.
Object.isExtensible()StaticIntegrityNon-mutatingES5Returns true if new properties can be added to the object. Objects are extensible by default. Frozen, sealed, and preventExtensions objects are non-extensible. Primitive values are never extensible.
Object.isExtensible(obj)→ booleanParams: obj — The object to check.
Object.getPrototypeOf()StaticPrototype ChainNon-mutatingES5Returns the prototype (i.e., the value of the internal [[Prototype]] property) of the specified object. Returns null for objects created with Object.create(null). The standard alternative to the non-standard __proto__ property.
Object.getPrototypeOf(obj)→ object | nullParams: obj — The object whose prototype is to be returned.
Object.setPrototypeOf()StaticPrototype ChainMutates objectES2015Sets the prototype of a specified object to another object or null. Significantly slower than setting the prototype at creation time via Object.create(). Prefer Object.create() when possible for performance.
Object.setPrototypeOf(obj, proto)→ object (same reference)Params: obj — The object whose prototype is to be set; proto — The new prototype object or null.
Object.is()StaticComparisonNon-mutatingES2015Determines whether two values are the same value using SameValue comparison. Similar to === but correctly handles two edge cases: NaN === NaN is false (buggy), but Object.is(NaN, NaN) is true; -0 === +0 is true (buggy), but Object.is(-0, +0) is false.
Object.is(value1, value2)→ booleanParams: value1 — The first value to compare; value2 — The second value to compare.
Object.hasOwn()StaticComparisonNon-mutatingES2022Returns true if the specified object has the given property as its own (not inherited) property. The modern, safer alternative to obj.hasOwnProperty() — works even on objects created with Object.create(null) that have no prototype.
Object.hasOwn(obj, prop)→ booleanParams: obj — The object to check; prop — The string name or Symbol of the property to test.
hasOwnProperty()PrototypeIntrospectionNon-mutatingES3Returns true if the object has the specified property as its own (not inherited) property. Note: fails on objects created with Object.create(null) since they have no hasOwnProperty method. Prefer Object.hasOwn() (ES2022) for safety.
obj.hasOwnProperty(prop)→ booleanParams: prop — The string name or Symbol of the property to test.
isPrototypeOf()PrototypeIntrospectionNon-mutatingES3Tests whether the calling object exists anywhere in the prototype chain of another object. Unlike instanceof, this works with any object as the prototype, not just constructor functions.
proto.isPrototypeOf(obj)→ booleanParams: obj — The object whose prototype chain will be searched.
propertyIsEnumerable()PrototypeIntrospectionNon-mutatingES3Returns true if the specified property is the object's own enumerable property. A property is enumerable if it appears in for...in loops and Object.keys(). Most user-defined properties are enumerable; built-in prototype properties are not.
obj.propertyIsEnumerable(prop)→ booleanParams: prop — The name of the property to test.
toString()PrototypeConversionNon-mutatingES1Returns a string representing the object. The default Object.prototype implementation returns "[object Object]". Most built-in types override this. Call Object.prototype.toString.call(value) to reliably detect a value's type (e.g., "[object Array]").
obj.toString()→ stringParams: No parameters.
valueOf()PrototypeConversionNon-mutatingES1Returns the primitive value of the specified object. The default implementation returns the object itself. JavaScript calls this automatically for type coercion (e.g., in arithmetic). Override valueOf() in custom classes to control coercion behavior.
obj.valueOf()→ object | primitiveParams: No parameters.
toLocaleString()PrototypeConversionNon-mutatingES3Returns a locale-sensitive string representation. The base Object.prototype implementation simply calls toString(), but Number, Date, and Array override it with locale-aware formatting. Accepts optional locale and options parameters.
obj.toLocaleString(locales?, options?)→ stringParams: locales — A BCP 47 language tag or array of tags (optional); options — Locale-specific formatting options (optional).
You need to merge two objects but Object.assign() does a shallow copy — nested objects are still references. Or you want to iterate an object’s entries but can’t remember whether Object.entries() includes inherited properties (it doesn’t). Or you need Object.groupBy() (ES2024) and aren’t sure of the syntax. With 20+ static methods and the distinction between own/inherited, enumerable/non-enumerable, and configurable/writable properties, Object has more depth than most developers realize.
Why This Reference (Not the Object Explorer)
PureDevTools has a JavaScript Object Explorer for visually inspecting nested objects and generating code. This reference covers all Object static and prototype methods — keys, values, entries, assign, freeze, create, defineProperty, hasOwn, groupBy, and more — with signatures, parameters, return values, and mutating badges.
What Are JavaScript Object Methods?
JavaScript’s Object constructor provides a rich set of static methods for working with objects — enumerating properties, composing new objects, controlling property attributes, managing prototypes, and enforcing immutability. Every object instance also inherits a small set of prototype methods from Object.prototype.
Understanding these methods — and whether they mutate the original object — is essential for writing predictable, safe JavaScript. This reference covers all major static and prototype methods with signatures, parameters, return values, ES version info, and runnable examples.
Static Methods vs Prototype Methods
Static Methods
Static methods are called directly on the Object constructor:
Object.keys(obj)
Object.assign(target, source)
Object.freeze(obj)
They are the primary API for creating, inspecting, and transforming objects without touching the prototype chain.
Prototype Methods
Prototype methods are inherited by every object instance from Object.prototype:
obj.hasOwnProperty('key')
obj.toString()
These are available on all objects (unless the prototype chain is deliberately severed with Object.create(null)).
Enumeration Methods
Enumeration methods allow you to extract the keys, values, or entries of an object as arrays — enabling functional patterns like map, filter, and reduce over plain objects.
Object.keys / Object.values / Object.entries
const user = { name: 'Alice', age: 30, role: 'admin' };
Object.keys(user); // ['name', 'age', 'role']
Object.values(user); // ['Alice', 30, 'admin']
Object.entries(user); // [['name','Alice'], ['age',30], ['role','admin']]
All three only include own enumerable string-keyed properties — they skip inherited properties, non-enumerable properties, and Symbol-keyed properties.
Object.fromEntries
Object.fromEntries() is the counterpart to Object.entries() — it converts an iterable of [key, value] pairs back into an object:
// Transform object values functionally
const prices = { apple: 1.5, banana: 0.75, cherry: 3.0 };
const discounted = Object.fromEntries(
Object.entries(prices).map(([k, v]) => [k, v * 0.9])
);
console.log(discounted); // { apple: 1.35, banana: 0.675, cherry: 2.7 }
It also accepts Map instances directly:
const map = new Map([['x', 10], ['y', 20]]);
console.log(Object.fromEntries(map)); // { x: 10, y: 20 }
Composition Methods
Object.assign — Shallow Merge
const target = { a: 1 };
const result = Object.assign(target, { b: 2 }, { c: 3 });
// target and result are the same reference: { a: 1, b: 2, c: 3 }
Caution: Object.assign mutates the target. To merge without mutation, spread into a new object:
const merged = { ...defaults, ...overrides }; // non-mutating
Object.create — Prototype-Based Inheritance
const vehicleProto = {
describe() { return this.make + ' ' + this.model; }
};
const car = Object.create(vehicleProto);
car.make = 'Toyota';
car.model = 'Camry';
console.log(car.describe()); // 'Toyota Camry'
Pass null to create a truly empty object with no prototype (a “pure dictionary”):
const dict = Object.create(null);
// dict has no .toString, .hasOwnProperty, or any other inherited method
dict.key = 'value';
Object.groupBy (ES2024)
Groups array elements by a computed key:
const products = [
{ name: 'Widget', category: 'hardware' },
{ name: 'Plugin', category: 'software' },
{ name: 'Gadget', category: 'hardware' },
];
const byCategory = Object.groupBy(products, p => p.category);
// { hardware: [...], software: [...] }
Property Definition & Inspection
Property Descriptors
Every property has a descriptor — an object controlling its behaviour:
| Attribute | Data Property | Accessor Property | Default |
|---|---|---|---|
value | ✓ | — | undefined |
writable | ✓ | — | false |
get | — | ✓ | undefined |
set | — | ✓ | undefined |
enumerable | ✓ | ✓ | false |
configurable | ✓ | ✓ | false |
const obj = {};
Object.defineProperty(obj, 'MAX', {
value: 100,
writable: false,
enumerable: true,
configurable: false,
});
console.log(obj.MAX); // 100
// obj.MAX = 200; // silently fails, or throws in strict mode
Getting Property Descriptors
const desc = Object.getOwnPropertyDescriptor(obj, 'MAX');
// { value: 100, writable: false, enumerable: true, configurable: false }
// Get ALL descriptors at once
const allDescs = Object.getOwnPropertyDescriptors(obj);
Including Non-Enumerable and Symbol Properties
// Object.keys only returns enumerable string keys
// Use getOwnPropertyNames for non-enumerable string keys
Object.getOwnPropertyNames(obj); // includes non-enumerable string props
// Use getOwnPropertySymbols for Symbol-keyed props
const sym = Symbol('tag');
const obj2 = { [sym]: 'value', name: 'Alice' };
Object.getOwnPropertySymbols(obj2); // [Symbol(tag)]
Object Integrity (Immutability)
JavaScript provides three levels of object locking, each progressively more restrictive:
| Level | Add props | Delete props | Change values |
|---|---|---|---|
preventExtensions | ✗ | ✓ | ✓ |
seal | ✗ | ✗ | ✓ |
freeze | ✗ | ✗ | ✗ |
// preventExtensions — can't add new properties
const a = Object.preventExtensions({ x: 1 });
delete a.x; // still works
a.y = 2; // silently ignored
// seal — can't add or delete, but can modify values
const b = Object.seal({ x: 1 });
b.x = 99; // works
delete b.x; // silently ignored
b.y = 2; // silently ignored
// freeze — fully immutable (shallow)
const c = Object.freeze({ x: 1 });
c.x = 99; // silently ignored
Shallow vs Deep Freeze
Object.freeze() is shallow. Nested objects are still mutable:
const config = Object.freeze({
db: { host: 'localhost', port: 5432 }
});
config.db.port = 9999; // This WORKS — config.db is not frozen!
console.log(config.db.port); // 9999
For deep immutability, recursively freeze nested objects:
function deepFreeze(obj) {
Object.getOwnPropertyNames(obj).forEach(name => {
const val = obj[name];
if (typeof val === 'object' && val !== null) deepFreeze(val);
});
return Object.freeze(obj);
}
Prototype Chain Methods
Object.getPrototypeOf / Object.setPrototypeOf
function Shape(color) { this.color = color; }
const circle = new Shape('red');
// Read prototype
console.log(Object.getPrototypeOf(circle) === Shape.prototype); // true
// Change prototype (avoid in hot paths — very slow)
const logger = { log() { console.log(JSON.stringify(this)); } };
Object.setPrototypeOf(circle, logger);
circle.log(); // {"color":"red"}
Object.is — Precise Equality
Object.is() is the SameValue comparison — more precise than === for two edge cases:
// NaN comparison — === is wrong here
console.log(NaN === NaN); // false ← incorrect
console.log(Object.is(NaN, NaN)); // true ← correct
// Signed zero — === is wrong here
console.log(-0 === +0); // true ← incorrect
console.log(Object.is(-0, +0)); // false ← correct
Object.hasOwn (ES2022) — Safe Own Property Check
The modern replacement for obj.hasOwnProperty():
// Works even on prototype-less objects
const dict = Object.create(null);
dict.foo = 'bar';
// dict.hasOwnProperty('foo') → TypeError (no prototype!)
console.log(Object.hasOwn(dict, 'foo')); // true ← safe
Prototype Methods
hasOwnProperty vs Object.hasOwn
const obj = { name: 'Alice' };
// Old way (can fail on null-prototype objects)
console.log(obj.hasOwnProperty('name')); // true
console.log(obj.hasOwnProperty('valueOf')); // false
// Modern way (ES2022) — always safe
console.log(Object.hasOwn(obj, 'name')); // true
isPrototypeOf
Tests whether an object exists in the prototype chain:
function Foo() {}
function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
const b = new Bar();
console.log(Foo.prototype.isPrototypeOf(b)); // true
console.log(Bar.prototype.isPrototypeOf(b)); // true
propertyIsEnumerable
Checks if a property is both own and enumerable:
const obj = {};
Object.defineProperty(obj, 'hidden', { value: 1, enumerable: false });
obj.visible = 2;
console.log(obj.propertyIsEnumerable('visible')); // true
console.log(obj.propertyIsEnumerable('hidden')); // false
console.log(obj.propertyIsEnumerable('toString')); // false (inherited)
toString for Type Detection
Use Object.prototype.toString.call() for reliable type detection:
const typeOf = (v) => Object.prototype.toString.call(v).slice(8, -1);
typeOf([]); // 'Array'
typeOf(null); // 'Null'
typeOf(undefined); // 'Undefined'
typeOf(new Map()); // 'Map'
typeOf(/regex/); // 'RegExp'
typeOf(42); // 'Number'
typeOf(Symbol()); // 'Symbol'
valueOf for Coercion Control
Override valueOf() to control how your objects behave in arithmetic:
class Vector {
constructor(x, y) { this.x = x; this.y = y; }
valueOf() { return Math.sqrt(this.x ** 2 + this.y ** 2); } // magnitude
toString() { return `Vector(${this.x}, ${this.y})`; }
}
const v = new Vector(3, 4);
console.log(v + 0); // 5 (calls valueOf → magnitude)
console.log(`${v}`); // 'Vector(3, 4)' (calls toString)
Common Patterns
Deep Clone (Structured Clone)
// Modern — use structuredClone() (not Object.assign or spread)
const original = { a: 1, nested: { b: 2 } };
const clone = structuredClone(original);
clone.nested.b = 99;
console.log(original.nested.b); // 2 — original unchanged
Object to Map
const obj = { a: 1, b: 2, c: 3 };
const map = new Map(Object.entries(obj));
map.get('a'); // 1
Invert an Object
const original = { a: 1, b: 2, c: 3 };
const inverted = Object.fromEntries(
Object.entries(original).map(([k, v]) => [v, k])
);
console.log(JSON.stringify(inverted)); // {"1":"a","2":"b","3":"c"}
Pick / Omit Object Keys
const user = { id: 1, name: 'Alice', password: 'secret', role: 'admin' };
// Pick
const { name, role } = user;
const picked = { name, role };
// Omit
const { password: _pw, ...safe } = user;
console.log(JSON.stringify(safe)); // {"id":1,"name":"Alice","role":"admin"}
FAQ
What is the difference between Object.keys, Object.values, and Object.entries?
All three enumerate own enumerable string-keyed properties. Object.keys() returns just the property names as a string[]. Object.values() returns just the property values as any[]. Object.entries() returns both as [string, any][] pairs. All three skip inherited properties, non-enumerable properties, and Symbol-keyed properties.
What is the difference between Object.freeze, Object.seal, and Object.preventExtensions?
These provide three levels of restriction. preventExtensions only prevents adding new properties — existing properties can still be deleted or changed. seal prevents adding and deleting properties but allows changing existing values. freeze prevents all modifications — the most restrictive. All three are shallow: nested objects are not affected.
When should I use Object.create(null)?
Use Object.create(null) when you need a truly empty object with no prototype (a “pure dictionary”). This avoids conflicts between your keys and inherited property names like toString, hasOwnProperty, or constructor. Common in polyfills, caches, and cases where you use the object as a lookup table.
What is the difference between Object.hasOwn and hasOwnProperty?
Both check if a property is an own property (not inherited). hasOwnProperty is a prototype method that fails (throws TypeError) on objects created with Object.create(null), since those objects have no prototype and therefore no hasOwnProperty method. Object.hasOwn() (ES2022) is a static method that always works safely. Prefer Object.hasOwn() in modern code.
Why does Object.assign only do a shallow copy?
Object.assign copies own enumerable property values. For objects, it copies the reference — not a deep clone. To deeply clone an object, use structuredClone() (modern) or JSON.parse(JSON.stringify(obj)) (simple but limited). To copy including getters and setters, use Object.create(proto, Object.getOwnPropertyDescriptors(src)).
What does Object.is(NaN, NaN) return and why does it differ from ===?
Object.is(NaN, NaN) returns true. The === operator follows the IEEE 754 floating-point standard, which defines NaN !== NaN. Object.is() implements the ECMAScript SameValue algorithm, which treats NaN as equal to itself and distinguishes -0 from +0 — two cases where === produces counterintuitive results.
Is my code sent to a server when I use the “Try it” examples?
No. All code execution happens entirely in your browser using JavaScript. Nothing is sent to any server.