배열 구조 분해 할당
배열이나 객체의 구조에 맞게 바로 개별 변수에 값을 할당하는 방법으로 필요한 값만 추출하여 변수에 할당할 수 있다. const numbers = [1,2,3] const a = numbers[0] //1const b = numbers[1] //2const c = numbers[2] //3 console.log(a,b,c) //1 2 3 numbers[0] - numbers의 첫번째 numbers[1] - numbers의 두번째numbers[2] - numbers의 세번째 const numbers = [1,2,3]const [a,b,c] = numbersconsole.log(a,b,c) //1 2 3 구조 분해 할당 문법은 실제 데이터와 같은 구조를 만들어서 원한느 값을 개별 변수에 ..
전개연산자 (Spread operator)
전개: 배열데이터와 객체데이터 안쪽에 있는 데이터를 껍데기를 날려버리고 풀어서 전개한다 spread 풀어헤친다 ... 을 붙여 자신을 감싸고 있는 전개연산자(...)와 대괄호[] / 중괄호 {}를 날려버림 //배열데이터const numbers = [1,2,3]console.log(numbers) //[1,2,3]console.log(...[1,2,3]) // 1 2 3 const n1 = [1,2,3]const n2 = [2,3,4]const n3 = n1.concat(n2)const n4 = [...n1, ...n2]console.log(n3) // [1,2,3,2,3,4]console.log(n4) // [1,2,3,2,3,4] n3 = n1 + concat을 이용해 (n2)를 ..