This article is a mirror article of machine translation, please click here to jump to the original article.

View: 10515|Reply: 0

[JavaScript] Front-end Object.assign() usage

[Copy link]
Posted on 6/4/2019 1:03:16 PM | | |
The Object.assign() method is used to copy the values of all enumerable attributes from one or more source objects to the target object. It will return to the target object.

const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };

const returnedTarget = Object.assign(target, source);

console.log(target);
// expected output: Object { a: 1, b: 4, c: 5 }

console.log(returnedTarget);
// expected output: Object { a: 1, b: 4, c: 5 }

targetThe original object will be changed.
The first parameter of the Object.assign method is the target object, and the subsequent arguments are all source objects.

Note that if the target object has a property of the same name as the source object, or if multiple source objects have a property of the same name, the subsequent property overrides the previous property.






Previous:Angular questions about getting Matrix URLs and normal URL query strings
Next:Use fetch instead of ajax request post delivery method
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com