[JavaScript] 16. 구조분해할당

서회정's avatar
Jan 28, 2026
[JavaScript] 16. 구조분해할당

💡
배열이나 객체에 저장된 여러개의 값들은 분해해서 각각 다른 변수에 할당하는 문법
 

1. 배열의 구조 분해 할당

// 1. 배열의 구조분해할당 let arr = [1, 2, 3]; let one = arr[0]; let two = arr[1]; let three = arr[2];
⇒ 배열이 길어지는 경우에는 코드도 길어지고 불편함!
 
let [one, two, three] = arr;
notion image
 
let arr = [1, 2, 3]; let [one, two, three] = arr; console.log(one, two, three);
notion image
 

2. 객체의 구조 분해 할당

// 2. 객체의 구조 분해 할당 let person = { name: "서회정", age: 32, hobby: "테니스", }; let { name, age, hobby } = person; console.log(name, age, hobby);
notion image
 

✅ 기존의 키값이 아닌 다른 이름의 변수로 저장할 수도 있다.

let { name, age: myAge, hobby } = person; console.log(name, myAge, hobby); // 서회정 32 테니스
 

3. 객체의 구조 분해 할당을 이용해서 함수의 매개변수를 받는 방법

// 3. 객체의 구조 분해 할당을 이용해서 함수의 매개변수를 받는 방법 const func = ({ name, age, hobby }) => { console.log(name, age, hobby); }; func(person);
  • 꼭 객체를 넘겨야 구조 분해 할당이 가능하다
Share article

clubnerdy