거북이개발자

[ES6] Destructuring Assignment 본문

Web/ES6

[ES6] Destructuring Assignment

류정식 2021. 2. 7. 13:29

1. Destructuring Assignment

 

(1)일반적 객체내 값 접근시

const student1={
  name : 'Ryu',
  age : 18,
};


{
   const name=student1.name;
   const age=student1.age;
};

이런식으로 각각의 요소를 객체.요소와 같은 식으로 접근해줬다.

 

 

 

 

(2) Destructuring Assignment-객체

const student1={
  name : 'Ryu',
  age : 18,
};

{
  const{name, age}=student1;
  console.log(name, age);

};

 

const{name, age}=student1;을 통해서 name, age로 바로 접근이 가능하다.

 

 

 

 

(3) Destructuring Assignment-배열

const star=['☆', '★'];

{
const [first, second]=star;
console.log(first, second);
}

배열도 이런식으로 간단하게 사용이 가능하다.

'Web > ES6' 카테고리의 다른 글

[ES11] Optional chaining  (0) 2021.02.07
[ES6] Template Literals  (0) 2021.02.07
[ES6] Default parameters  (0) 2021.02.07
[ES6] Spread Syntax  (0) 2021.02.07
[ES6] Shorthand property names  (0) 2021.02.07
Comments