Object.defineProperties() method

The Object.defineProperties function is utilized to create new properties or alter existing ones directly on an object, returning the modified object.

Syntax:

Example

Object.defineProperties(obj, props)

Parameter

Obj : The entity upon which properties can be established or altered.

Props: An entity whose own enumerable attributes serve as descriptors for the properties that are intended to be defined or altered.

Return:

This technique returns an object that was provided as an argument to the function.

Browser Support:

Chrome Yes
Edge Yes
Firefox 1.5
Opera Yes

Example 1

Example

const object1 = {};
Object.defineProperties(object1, {
  property1:{
value: 44, }
 });
console.log(object1.property1);

Output:

Example 2

Example

const object1 = {};
Object.defineProperties(object1, {
  property1: {
    value: 142,
    value: 422,
    value: 423,
    },
 property2: {}
});
console.log(object1.property1);

Output:

Example 3

Example

const obj = {};
Object.defineProperties(obj, {
  property1: {
    value: 142,
    value: 422,
    value: 423,
    },
  property2: {
  value: 22,
  value: 12,}
});
console.log(obj.property1,obj.property2);

Output:

Output

423 
12

Input Required

This code uses input(). Please provide values below: