Whenever I need to copy one object to another in JS, I just cast it to a primitive:
var newObject = JSON.stringify(oldObject);
Then when I need to use it:
var evenNewerObj = JSON.parse(newObject);
Hope this helps someone.
More Related Contents:
- JavaScript code trick: What’s the value of foo.x
- In JavaScript, is chained assignment okay?
- Can a JavaScript object property refer to another property of the same object? [duplicate]
- How to get all the values associated with an object in array?
- How to remove all duplicates from an array of objects?
- Creating object with dynamic keys [duplicate]
- How do I create a dynamic key to be added to a JavaScript object variable [duplicate]
- Sort array of objects by single key with date value
- Is it possible to get the non-enumerable inherited property names of an object?
- Operator precedence with Javascript Ternary operator
- How do you check if a JavaScript Object is a DOM Object?
- How to add an object to an array
- Iterate through object properties
- How to display all methods of an object?
- Clone Object without reference javascript [duplicate]
- Why Array.indexOf doesn’t find identical looking objects
- Which way is best for creating an object in JavaScript? Is `var` necessary before an object property?
- In javascript how can I dynamically get a nested property of an object
- How do you create a method for a custom object in JavaScript?
- Uncaught TypeError: Object.values is not a function JavaScript
- traversing through JSON string to inner levels using recursive function
- Set undefined javascript property before read
- Combining two arrays to form a javascript object
- Get values from an object in JavaScript [duplicate]
- Convert string with dot notation to JSON
- Object referencing its own property on initialization [duplicate]
- Converting Array of Objects into Array of Arrays
- Using non-ASCII character as JavaScript object key [duplicate]
- Difference between ( for… in ) and ( for… of ) statements?
- Find object having maximum value for the `id` property in an array of objects