JS: Object .defineProperties

By Xah Lee. Date: . Last updated: .
Object.defineProperties(obj, {key1: descriptor1}, {key2: descriptor2}, etc)
  • Create or modify one or more properties.
  • Return the modified obj.
  • The descriptor1, descriptor2, etc are Property Descriptor.
const jj = {};

// add 2 properties with attributes
Object.defineProperties(
 jj,
 {
  dog: {
   value: 1,
   writable: true,
   enumerable: true,
   configurable: true,
  },
  cat: {
   value: 2,
   writable: true,
   enumerable: true,
   configurable: true,
  },
 },
);

console.log(jj);
// { dog: 1, cat: 2 }