copy object javascript
var x = {myProp: "value"};
var y = Object.assign({}, x);
copy object javascript
var x = {myProp: "value"};
var y = Object.assign({}, x);
copy object javascript
// es6
const obj = {name: 'john', surname: 'smith'};
const objCopy = {...obj};
javascript clone object
var x = {myProp: "value"};
var xClone = Object.assign({}, x);
//Obs: nested objects are still copied as reference.
clone an object javascript
//returns a copy of the object
function clone(obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us