- 일반밸류
var str = "Tomorrow is on Friday";
var str2 = str;
str = "Tomorrow is not on Saturday";
console.log(str);
console.log(str2);
- 객체 복사
var obj = {name: "john", age: 20, school: "seneca"};
var objNested = {
name: "john",
age: 20,
school: {name: "seneca", course: "computer", class: ["tue", "thu", "fri"]},
family: ["dad","mom","brother"]
};
var obj2 = obj;
obj2.name = "tom";
console.log(obj);
console.log(obj2);
obj.age = 30;
console.log(obj);
console.log(obj2);
var obj2 = {...obj};
obj.name = "tom";
consol.log(obj);
console.log(obj2);
var obj3 = {...obj, name: "park"};
var objNested2 = {...objNested};
objNested.school.name = "humber";
objNested.family[0] = "father";
var obj2 = Object.assign({}, obj);
obj.name = "tom";
consol.log(obj);
console.log(obj2);
var objNested2 = Object.assign({}, objNested);
objNested.school.name = "humber";
objNested.family[0] = "father";
var obj2 = JSON.parse(JSON.stringify(obj));
obj.name = "tom";
consol.log(obj);
console.log(obj2);
var objNested2 = JSON.parse(JSON.stringify(objNested));
objNested.school.name = "humber";
objNested.family[0] = "father";
var obj2 = $.extend(true, {}, obj);
obj.name = "tom";
consol.log(obj);
console.log(obj2);
var objNested2 = $.extend(true,{},objNested);
objNested.school.name = "humber";
objNested.family[0] = "father";
- 배열복사
var arr = ["baseball", "soccer", "basketball", "ballyball", "handball"];
var arrNested = ["baseball", "soccer", "basketball",
{america: "football", canada: "hockey",
north: ["america", "canada", "mexico"],
south: {win:"brazil", lose:"germany"}
},
"handball", [32,54,30,20], ["add", "substract", "multiple", "devide"]
];
var arr2 = arr;
arr[0] = "softball";
console.log(arr);
console.log(arr2);
var arr2 = Array.from(arr);
arr[0] = "softball";
console.log(arr);
console.log(arr2);
var arrNested2 = Array.from(arrNested);
arrNested[3].america = "superball";
arrNested[3].north[1] = "CANADA";
arrNested[3].south.lose = "spain";
arrNested[5][3] = 300;
arrNested[6][2] = "minus"
console.log(arrNested);
console.log(arrNested2);
var arr2 = arr.slice(0);
arr[0] = "softball"
console.log(arr);
console.log(arr2);
var arrNested2 = arrNested.slice(0);
arrNested[3].america = "superball";
arrNested[3].north[1] = "CANADA";
arrNested[3].south.lose = "spain";
arrNested[5][3] = 300;
arrNested[6][2] = "minus"
console.log(arrNested);
console.log(arrNested2);
var arr2 = [...arr];
arr[0] = "softball"
console.log(arr);
console.log(arr2);
var arrNested2 = [...arrNested];
arrNested[3].america = "superball";
arrNested[3].north[1] = "CANADA";
arrNested[3].south.lose = "spain";
arrNested[5][3] = 300;
arrNested[6][2] = "minus"
console.log(arrNested);
console.log(arrNested2);
var arr2 = arr.map(x => x);
arr[0] = "softball"
console.log(arr);
console.log(arr2);
var arrNested2 = arrNested.map(x => x);
arrNested[3].america = "superball";
arrNested[3].north[1] = "CANADA";
arrNested[3].south.lose = "spain";
arrNested[5][3] = 300;
arrNested[6][2] = "minus"
console.log(arrNested);
console.log(arrNested2);
var arr2 = JSON.parse(JSON.stringify(arr));
arr[0] = "softball"
console.log(arr);
console.log(arr2);
var arrNested2 = JSON.parse(JSON.stringify(arrNested));
arrNested[3].america = "superball";
arrNested[3].north[1] = "CANADA";
arrNested[3].south.lose = "spain";
arrNested[5][3] = 300;
arrNested[6][2] = "minus"
console.log(arrNested);
console.log(arrNested2);
var arr2 = $.extend(true,[],arr);
arr[0] = "softball"
console.log(arr);
console.log(arr2);
var arrNested2 = $.extend(true,[],arrNested);
arrNested[3].america = "superball";
arrNested[3].north[1] = "CANADA";
arrNested[3].south.lose = "spain";
arrNested[5][3] = 300;
arrNested[6][2] = "minus"
console.log(arrNested);
console.log(arrNested2);