JavaScript Object.assign()
- Previous page assign()
- Next page constructor
- Go up one level JavaScript Object Reference Manual
Definition and usage
Object.assign()
Methods used to copy the properties of one or more source objects to the target object.
Related methods:
Object.assign()
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))
Parameter
Parameter | 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).
Starting from 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
- Go up one level JavaScript Object Reference Manual