Object.getPrototypeOf()
getPrototypeOf(obj) Returns:
object | null · Added in vES5 · Updated March 16, 2026 · Object Methods object prototype prototype-of
The Object.getPrototypeOf() method returns the prototype of the specified object. This gives you access to an object’s internal [[Prototype]], which determines the object’s inheritance chain. Understanding prototypes is fundamental to JavaScript’s object-oriented features.
Syntax
Object.getPrototypeOf(obj)
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | object | The object whose prototype to return |
Examples
Basic prototype retrieval
const proto = { greet() { return 'hello'; } };
const obj = Object.create(proto);
console.log(Object.getPrototypeOf(obj) === proto); // true
With a plain object
const user = { name: 'Alice' };
console.log(Object.getPrototypeOf(user) === Object.prototype); // true
With an array
const numbers = [1, 2, 3];
console.log(Object.getPrototypeOf(numbers) === Array.prototype); // true
With null prototype
const nullProto = Object.create(null);
console.log(Object.getPrototypeOf(nullProto)); // null
Checking class inheritance
class Animal {
constructor(name) {
this.name = name;
}
}
const dog = new Animal('Rex');
console.log(Object.getPrototypeOf(dog) === Animal.prototype); // true
Common Patterns
Verify object type without instanceof
function isArrayLike(obj) {
return Object.getPrototypeOf(obj) === Array.prototype;
}
console.log(isArrayLike([1, 2, 3])); // true
console.log(isArrayLike({ length: 3 })); // false
Walk the prototype chain
const grandparent = { a: 1 };
const parent = Object.create(grandparent);
const child = Object.create(parent);
let current = child;
const chain = [Global_Objects::eval];
while (current) {
chain.push(current);
current = Object.getPrototypeOf(current);
}
console.log(chain.length); // 3
See Also
- Object.create() — Create object with specified prototype
- Object.keys() — Get array of object keys