ES6 - Object.setPrototypeOf



Copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.

Syntax

In the syntax given below target is the target object and sources is the source object(s).

Object.assign(target, ...sources)

Example

<script>
   //Object.assign()
   let obj1 = {x:10},
      obj2 = {y:20},
      obj3 = {z:30}

   Object.assign(obj1,obj2,obj3)
   console.log("obj 1",obj1)

</script>

The output of the above code will be as mentioned below −

obj 1 {x: 10, y: 20, z: 30}
Advertisements