I\'m trying to make a simple function that will swap the values of two properties on the same or different global objects.
object1 = {\"key 1\":\"value 1\"}
I would do it as follows:
var obj1 = {
"key1" : "value1",
"key2" : "Value2"
};
var obj2 = {
"key3" : "value3",
"key4" : "Value4"
};
function swap(sourceObj, sourceKey, targetObj, targetKey) {
var temp = sourceObj[sourceKey];
sourceObj[sourceKey] = targetObj[targetKey];
targetObj[targetKey] = temp;
}
swap(obj1, "key1", obj1, "key2");
swap(obj1, "key1", obj2, "key4");