Explorer
Node.js

Write a function `getPrototypeChain(obj)` that returns an array of constructor names in the prototype chain.

Problem Statement

Write a function `getPrototypeChain(obj)` that returns an array of constructor names in the prototype chain.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Object.getPrototypeOf(obj) returns the prototype of obj. šŸ’” Hint 2: Keep traversing until you reach null. šŸ’” Hint 3: Push constructor.name for each prototype that has a constructor. āœ… Solution: ```javascript function getPrototypeChain(obj) { const chain = []; let proto = Object.getPrototypeOf(obj); while (proto) { if (proto.constructor) chain.push(proto.constructor.name); proto = Object.getPrototypeOf(proto); } return chain; } ```

Prototype Chain

Medium
Write a function `getPrototypeChain(obj)` that returns an array of constructor names in the prototype chain.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
["Array","Object"]