
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Copy objects with Object.assign() in JavaScript
The Object.assign() method is used to copy one or more source objects to a target object. It invokes getters and setters since it uses both 'get' on the source and 'Set' on the target.
The syntax is as follows −
Object.assign(target, ...source objects);
Following is the code to copy object −
Example
var object = {first: second => second + 1000} var object2= Object.assign({}, object); console.log("The result="); console.log(object2.first(1000));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo102.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo102.js The result= 2000
- Related Articles
- How to assign values to an array with null/empty objects in JavaScript?
- How to shallow copy the objects in JavaScript?
- How to transform object of objects to object of array of objects with JavaScript?
- JavaScript: Sort Object of Objects
- How to import an Object with Sub Objects and Arrays in JavaScript?
- How would you deep copy an Object in Javascript?
- Converting array of objects to an object of objects in JavaScript
- How to merge objects into a single object array with JavaScript?
- Can we assign new property to an object using deconstruction in JavaScript?
- Convert object of objects to array in JavaScript
- Convert object to array of objects in JavaScript
- Converting array of objects to an object in JavaScript
- How do we copy objects in java?
- How Can You Copy Objects in Python?
- Shortest syntax to assign properties from function call to an existing object in JavaScript

Advertisements