Course recommendation:
- Previous page assign()
- Next page constructor
- Return to the previous level JavaScript object reference manual
JavaScript Object.assign()
Object.assign()
Definition and usage
Methods used to copy the properties of one or more source objects to the target object.
Object.assign()
Related methods:
Copy the properties of the source object to the target object.
Object.create()
Create a new object from an existing object.
Object.fromEntries()
Create an object from a list of key/value pairs.
instance // Create the target object const person1 = { firstName: "Bill", lastName: "Gates", age: 50, eyeColor: "blue" }; // Create the source object // Copy the properties of the source object to the target object Object.assign(person1, person2);
Syntax
Object.assign(target, source(s))
Parameters
Parameters | Description |
---|---|
target | Required. Target object. |
source | Required. One or more source objects. |
Return value
Type | Description |
---|---|
Object | Target object. |
Browser support
Object.assign()
Is a feature of ECMAScript6 (ES6).
Since June 2017, all modern browsers support ES6 (JavaScript 2015):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | April 2017 | June 2017 | September 2016 | June 2016 |
Object.assign()
Not supported in Internet Explorer.
- Previous page assign()
- Next page constructor
- Return to the previous level JavaScript object reference manual