JavaScript (ES2026) reference · Object Methods

JavaScript Object.defineProperties() Method

Add or change several properties at once using property descriptors, each with its own writable and enumerable flags.

JavaScript (ES2026) Since ES5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Object.defineProperties(obj, props)

Parameters

ParameterDescription
obj The object to inspect or change.
props An object mapping names to descriptors.

Return value

The object.

Examples

Two properties at onceTry it yourself
const user = {};
Object.defineProperties(user, {
  id: { value: 7, enumerable: true },
  secret: { value: "x", enumerable: false },
});
console.log(user, user.secret);

Output

{ id: 7 } x
Descriptors default to falseTry it yourself
const p = Object.defineProperties({}, { a: { value: 1, writable: true } });
p.a = 2;
console.log(p.a, Object.getOwnPropertyDescriptor(p, "a").enumerable);

Output

2 false

Version history

VersionChange
JavaScript ES5Added

Was this page helpful?