배열 및 객체의 분해

const comment = ["Hi", "Hello", "world"];

상수 변수인  comment에서 배열 안에 Hi와 Hello, world를 지니고 있다.

 

 

두개의 상수 또는 변수를 한번에 생성하는 법

const [first, second, third] = ["Hi", "Hello", "world"];
console.log(first);
console.log(second);

콘솔 결과는 각각 "Hi"와 "Hello"를 출력

 

const {name ,age} = {
name : "andy",
age : 31
};

위와 같이 객체를 분해하기 위해 중괄호 사용하며,

객체의 정의된 필드 이름을 사용해야 한다.

'JS' 카테고리의 다른 글

조건문과 반복문  (0) 2024.09.23
스프레드 연산자 (...)  (0) 2024.09.20
배열 및 배열 메서드  (0) 2024.09.13
JavaScript  (0) 2024.09.12
Import & Export  (0) 2024.09.11

+ Recent posts