clone a JavaScript object
var sheep={"height":20,"name":"Melvin"};
var clonedSheep=JSON.parse(JSON.stringify(sheep));
//note: cloning like this will not work with some complex objects such as: Date(), undefined, Infinity
// For complex objects try: lodash's cloneDeep() method or angularJS angular.copy() methodThe Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns 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 }
Also in JavaScript:
- how to get the first character of a string in javascript
- react native background image
- how to change the color using js
- express get full url
- telerik asp.net ajax error creating control
- how to check if object is undefined in javascript
- array from javascript
- jednorozeclinda
- javascript get first 10 characters of string
- javascript date method
- queryselector name attribute
- dynamic for loop react
- javascript element read attribute
- table row count in jquery
- disable mixed content via javascript
- How can I refresh a page with jQuery
- three.js sphere
- moment to javascript date
- Material-ui aircon icon
- react js text input with icon
- node ja sap concur
- jquery enforce important
- delete from list javascript
- javascript substring vs substr