JS - 전개연산자
전개연산자 전개연산자는 ... 이 키워드로 사용할 수 있다 const fruits = ['apple','banana','melon'] console.log(fruits) console.log(...fruits) function toObject(a,b,c) { return { a:a, b:b, c:c } } console.log(toObject(...fruits)) 위와 같이 ...을 사용하면 , 로 구분된 배열 데이터가 각각 전개된다 따라서 toObject 함수에 저렇게 넣게 된다면 각각 'apple','banana','melon' 이 배열 데이터가 매개변수로 각각 들어가 return 된다 이 결과를 전개연산자를 사용하지 않는다면 console.log(toObject(fruits[0],fruits[1],..
2021. 10. 18.
JS - 구조 분해 할당
자바스크립트에서 객체나 배열안의 값을 변수로 분해할수 있게 해주는 문법이다. const user = { name:'Lee', age:20000, email:'Lee@KOR.co.kr', address:'KOR' } const {name:hi,age,email,address} = user console.log(`사용자의 이름은 ${hi}입니다`) console.log(`사용자의 나이는 ${age}입니다`) console.log(`사용자의 이메일은 ${email}입니다`) console.log(`사용자의 주소는 ${address}입니다`) 배열에서도 가능하다 const fruits = ['apple','banana','melon'] const [a,b,c] = fruits console.log(a,b,c) ..
2021. 10. 18.