| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | dev_langs | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Object.assign Function (Object) (JavaScript) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
2dd6b312-dcd3-414e-8d53-088c6341c46d |
4 |
mikejo5000 |
mikejo |
ghogen |
Copies the values from one or more source objects to a target object.
Object.assign(target, ...sources );
target
Required. A object to which enumerable properties are copied.
...sources
Required. One or more objects from which enumerable properties are copied.
This function throws a TypeError if there is an assignment error, which terminates the copying operation. A TypeError will be thrown if a target property is not writable.
This function returns the target object. Only enumerable own properties are copied from the source object to the target object. You can use this function to merge or clone objects.
null or undefined sources are treated like empty objects and contribute nothing to the target object.
The following code example shows how to merge an object using Object.assign.
var first = { name: "Bob" };
var last = { lastName: "Smith" };
var person = Object.assign(first, last);
console.log(person);
// Output:
// { name: "Bob", lastName: "Smith" } The following example shows how to clone an object using Object.assign.
var obj = { person: "Bob Smith"};
var clone = Object.assign({}, obj); [!INCLUDEjsv12]