본문 바로가기
DEV/javascript

구조 분해 할당

by 스타월드 2022. 3. 20.
let options = {
  title: "Menu",
  width: 100,
  height: 200
};

let {title, width, height} = options;

alert(title);  // Menu
alert(width);  // 100
alert(height); // 200
let options = {
  title: "Menu",
  width: 100,
  height: 200
};

// { 객체 프로퍼티: 목표 변수 }
let {width: w, height: h, title} = options;

// width -> w
// height -> h
// title -> title

alert(title);  // Menu
alert(w);      // 100
alert(h);      // 200

'DEV > javascript' 카테고리의 다른 글

옵셔널 체이닝 '?.'  (0) 2022.03.20
스프레드 문법  (0) 2022.03.20
nullish - 널리쉬 병합 연산자 '??'  (0) 2022.03.19