Home JavaScript Object Methods getOwnPropertyDescriptors() JavaScript Object.getOwnPropertyDescriptors() Method Definition Object.getOwnPropertyDescriptors(obj) returns a plain object whose keys are the own property names and symbols of obj. Each value is a full property descriptor: value, writable, enumerable, configurable (or get/set for accessors).
Inherited properties are ignored. Use this when you need to copy or inspect flags — not just values — for example before Object.defineProperties() or Object.create().
Syntax Call Object.getOwnPropertyDescriptors() like this. Start with this line.
Object.getOwnPropertyDescriptors(obj) Call What it does Object.getOwnPropertyDescriptors(obj)Returns an object of every own property descriptor on obj.
Built into JavaScript. Call on Object — no import required.
Library declarations Object.getOwnPropertyDescriptors(obj) getOwnPropertyDescriptors(o: any): { [p: string]: PropertyDescriptor }; Parameters Parameter Description obj Required. The object whose own property descriptors you want. Primitives are boxed first.
Return Value Return Value Description object A new object mapping each own key (string or symbol) to its property descriptor.
Important
This returns descriptors , not property values. To copy both values and flags, pass the result to Object.defineProperties() or Object.create(proto, descriptors).
JavaScript Examples 1. Basic use 2. Non-enumerable 3. Copy with flags Example 1 — Basic Use Read descriptors for a small object and print a few flags.
var user = {
name: "Ada",
age: 36
};
var all = Object.getOwnPropertyDescriptors(user);
console.log(all.name.value);
console.log(all.name.writable);
console.log(all.age.enumerable); How It Works Build an object Normal object literals create data properties that are writable, enumerable, and configurable.Read all descriptors Object.getOwnPropertyDescriptors(user) returns one descriptor object per own key.Inspect flags Each descriptor has value plus writable, enumerable, and configurable.Example 2 — Hidden Properties Descriptors include non-enumerable own properties that Object.keys() skips.
var box = {};
Object.defineProperty(box, "secret", {
value: 42,
enumerable: false,
writable: true,
configurable: true
});
console.log(Object.keys(box));
var desc = Object.getOwnPropertyDescriptors(box).secret;
console.log(desc.value);
console.log(desc.enumerable); How It Works Hide a property enumerable: false keeps secret out of Object.keys() and for...in.Still an own property getOwnPropertyDescriptors still returns it because the property belongs to box.Read the flags The descriptor shows the value 42 and that enumerable is false.Example 3 — Copy With Flags Clone an object while keeping non-enumerable properties by copying descriptors.
var source = {};
Object.defineProperty(source, "id", {
value: 7,
enumerable: false,
writable: false,
configurable: true
});
source.label = "item";
var copy = Object.create(
Object.getPrototypeOf(source),
Object.getOwnPropertyDescriptors(source)
);
console.log(copy.label);
console.log(Object.getOwnPropertyDescriptor(copy, "id").value);
console.log(Object.keys(copy)); How It Works Mix visible and hidden label is a normal enumerable property; id is non-enumerable.Copy descriptors Object.create(proto, descriptors) rebuilds the object with the same flags.Flags survive id is still there and still hidden from Object.keys().Compatibility
Browser & Runtime Support Object.getOwnPropertyDescriptors() arrived in ES2017 . It is Baseline and available in modern browsers and Node.js.
✓ Baseline · ES2017
Object.getOwnPropertyDescriptors() Supported in Chrome 54+, Firefox 50+, Safari 10+, Edge 15+, and Node.js 7+.
97% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support Object.getOwnPropertyDescriptors Excellent
Bottom line: Safe for modern apps. For older engines, copy one property at a time with Object.getOwnPropertyDescriptor().
Frequently Asked Questions What does Object.getOwnPropertyDescriptors() do? It returns an object that maps every own property name and symbol to its full property descriptor (value/flags or get/set).
Does it include inherited properties? No. Only own properties on the object itself are included. Prototype properties are skipped.
How is it different from getOwnPropertyDescriptor? getOwnPropertyDescriptor reads one key. getOwnPropertyDescriptors returns descriptors for all own keys at once.
Are symbol keys included? Yes. Symbol own properties appear as keys on the returned object, just like string keys.
Why use descriptors instead of Object.assign? Object.assign copies only enumerable string keys and loses writable/enumerable/configurable flags. Descriptors keep the full definition.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion