
비 구조화 할당(구조 분해 할당) 구문은 배열이나 객체의 속성을 해체하여 그 값을 개별 변수에 담을 수 있게 하는 JavaScript 표현식입니다.
let arr = ["one", "two", "three"];
let [one, two, three] = arr;
console.log(one, two, three);
swap
let a = 10;
let b = 20;
[a, b] = [b, a];
console.log(a, b);
객체일 때는
let object = { one: "one", two: "two", three: "three", name: "손흥민" };
let { name: myName, one, two, three. abc = "four" } = object;
console.log(one, two, three, myName, abc);
결과
one two three 손흥민 four
=> 순서가 아닌 키 값을 기준으로 할당한다.
소중한 정보 감사드립니다!