I've been reading about cloning and everyone seems to be using some complicated code. I guess that I might be doing it wrong, but it seems to be working, and when changing values of "cloned" object properties, my main object does not change.
var clonedObject ={};
//randomItem is main object, which I want to clone
for (var key in randomItem) {
if (randomItem.hasOwnProperty(key)) {
clonedObject[key] = {};
clonedObject[key] = randomItem[key];
}
};
return clonedObject;
It works for me, please tell me if there is something wrong with that? I am confused since this seems too easy compared to what other posts says about it(tho some of them are 7 years old). Thanks